arr-数组-Arr-array 遍历

实例说明:

let arr = [3, undefined, 1, 6];
function log(i: any) {
    console.log(i);
}
arr.map(log);// 3  undefined  1  6

语法

数组.map(回调函数, thisValue)

1. 说明

  1. 回调函数, 必须
    1. 回调函数的形参要求(按顺序):
      1. 一个接受数组元素的形参, 必须
      2. 一个接受数组元素索引的形参, 可选
      3. 一个接受数组对象的形参, 可选
  2. thisValue, 可选
    1. 修改回调函数中this的指向
      如果省略了 thisValue,或者传入 null、undefined,那么回调函数的 this 为全局对象。

2. 返回值:

返回一个新数组,数组中的元素为原始数组元素调用函数返回的值。