JS中的map

定义和用法:

map() 方法返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值。

map() 方法按照原始数组元素顺序依次处理元素。

注意: map() 不会对空数组进行检测。

注意: map() 不会改变原始数组。

语法

 array.map(function(currentValue,index,arr), thisValue) 

参考说明:

实例:

1 var nums=[10,20,30];
2     nums.map(function(value,index,arr){
3         document.write('value值为:'+value); //10 20 30
4         document.write('index值为:'+index); //0 1 2
5         document.write('arr值为:'+arr); //[10,20,30]
6     })

 

原文地址:https://www.cnblogs.com/daidechong/p/11211631.html