map()
方法定义在JavaScript的Array
中,它返回一个新的数组,数组中的元素为原始数组调用函数处理后的值。map()不会对空数组进行检测,不会改变原始数组。
具体语法
array.map(function(currentValue, index, arr), thisIndex)
forEach()中的function回调同样有三个参数**(currentValue元素值,index索引值,array原数组)**
thisValue
:可选。对象作为该执行回调时使用,传递给函数,用作"this
"的值。
// map
// 1. 与forEach相比,map()有返回值,默认return值为undefinede
// 2. 同样不能break打断
let arr = ['a', 'b', 'c']
let res = arr.map((value, index) => {
return value + '1'
});