ES6 - 数组方法 map()
map() 方法创建一个新数组,其结果是在此数组中的每个元素上调用提供的函数。
语法
array.map(callback[, thisObject]);
参数
callback − 从当前数组元素生成新数组元素的函数。
thisObject − 执行回调时用作 this 的对象。
返回值
返回创建的数组。
示例
var numbers = [1, 4, 9]; var roots = numbers.map(Math.sqrt); console.log("roots is : " + roots );
输出
roots is : 1,2,3