2018-06-16

  1. 【迭代阵列】   forEach循环访问数组, 并将当前元素及其索引交给函数:

    [ 'a', 'b', 'c' ].forEach(( elem, index) => {
        console.log(index + '.' + elem);
    });

    前面的代码生成以下输出:

    0. a
    1. b
    2. c
  2. elemmap通过将函数应用于现有数组的每个元素来创建新数组:
    > [1,2,3].map( x => x*x )
    [ 1, 4, 9 ]

猜你喜欢

转载自www.cnblogs.com/Longhua-0/p/9189526.html
今日推荐