var array1 = [1, 4, 9, 16];
map1=array1.map(Function.call,Number);
Why the output of map1 is [0,1,2,3], what this map function is doing?
Array.map function creates a new Array, with the results of calling the provided Function (Function.call) on every element in the Array that calls Array.map.
e.g.
// Store an initial Array of String values
var stringArray = ['Matt','Long','JavaScript'];
// Invoke Function for each value of Array
mapResult = stringArray.map((currentValue) => {
// Concatenate and return
return currentValue + ' Software';
});
// Log map result
console.log(mapResult);
You are passing in Number as the 'this' value to use, when executing callback for each value in the Array. In the result Array, each element is the result of calling the given Function on each value in the Array.
The Function.call method calls a Function with a given 'this' value and the arguments provided.