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