ES6 - Array Method map()


Advertisements

map() method creates a new array with the results of calling a provided function on every element in this array.

Syntax

array.map(callback[, thisObject]);   

Parameters

  • callback − Function that produces an element of the new Array from an element of the current one.

  • thisObject − Object to use as this when executing callback.

Return Value

Returns the created array.

Example

var numbers = [1, 4, 9]; 
var roots = numbers.map(Math.sqrt); 
console.log("roots is : " + roots );    

Output

roots is : 1,2,3 
es6_arrays.htm
Advertisements