.map() (JavaScript)

.map() creates a new array by running a function on every element of an existing array, without changing the original.

JavaScript

Examples

JavaScript

const nums = [1, 2, 3];
const doubled = nums.map(n => n * 2);
console.log(doubled);

Output:

[2, 4, 6]

See also

Back to the Dictionary