array.map()
The map() method of Array instances creates a new array populated with the results of calling a provided function on every element in the calling array.
The map() method of Array instances creates a new array populated with the results of calling a provided function on every element in the calling array.
let arrayNumbers = [2, 4, 6, 8, 10, 12];
arrayNumbers.forEach(print);
let arraySquares = arrayNumbers.map(square);
arraySquares.forEach(print);
let arrayCubes = arrayNumbers.map(cube);
arrayCubes.forEach(print);
function print(x) {
console.log(x);
}
function square(number) {
return Math.pow(number, 2);
}
function cube(number) {
return Math.pow(number, 3);
}