JS中的map

定义和用法

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

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

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

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

语法:

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

 参数说明:

实例:

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

猜你喜欢

转载自www.cnblogs.com/zhaoxinmei-123/p/8927259.html
今日推荐