文章目录
map
map 方法创建一个数组,其结果是该数组中每个元素调用一次回调函数的返回值
语法:arr.map(function callback(currentValue[, index[, array]]) {}[, thisArg])
callback:遍历数组中每个元素的回调函数,可以传入三个参数
currentValue:回调函数正在处理的数组中的当前元素
index:(可选)数组中正在处理的元素的索引
array:(可选)被调用的数组
thisArg:(可选)执行回调函数时指定的this值
返回值:一个由数组中每个元素执行一次回调函数的结果组成的数组
// 常用 map 方法
const arr = [1, 2, 3,