map()方法创建一个新数组,其结果是该数组中的每个元素都调用一个提供的回调函数后返回的结果。新数组
// ES6
let numbers = [1, 5, 10, 15];
let doubles = numbers.map( x => x ** 2); // doubles is now [1, 25, 100, 225]
// numbers is still [1, 5, 10, 15] const numbers = [2, 4, 8, 10];
let halves = numbers.map(x => x / 2); let numbers = [1, 4, 9];
let roots = numbers.map(Math.sqrt);
// roots is now [1, 2, 3]
// numbers is still [1, 4, 9]
参数:
第一个:回调函数,生成新数组元素
第二个:传入回到函数的this值