Monday, September 30, 2019

JavaScript Array map() Method


The method map() of array always creates a new array without modify the original array and the map method calls the provided function or execute the statement for each array elements

You can use map () method to iterate of each element of array instead of using JavaScript looping function like for or foreach method and it will reduce number of lines code to compare for or foreach method

Here is an example of map method to calculate the square value for each element of array

const sqrs = [1,2,3].map(x => x * x);

console.log(sqrs);

Output: Array [1, 4, 9]

another example of map method to calculate the square root of each element in the array

const sqrs = [4, 9, 16, 25].map(Math.sqrt);

console.log(sqrs);

Output: Array [2, 3, 4, 5]



No comments:

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...