前端

《javascript基础补充--Array》

2017-11-11  本文已影响19人  code追命

常用的

event

prototype

es6

event

prototype

返回值均为一个iterator//event next();

not be familiar with

Array.prototype.reduce (callback[,initialValue])

积累器

    [1,2,3,4].reduce((
        accumulator,
        currentValue,
        currentIndex,
        array
        )=>{
            return accumulator + currentValue
        },
        10
    )//=>20

Array.prototype.slice (start[,end])

复制器

    var arr1 = [1,2,3,4];
    var arr2 = arr1.slice(1,3);
    console.log(arr1);//=>[1,2,3,4]
    console.log(arr2);//=>[2,3]

Array.prototype.splice (start,deleteCount,[item1[,item2]])

移除器

    var arr1 = [1,2,3,4];
    var arr2 = arr1.splice(1,3);
    console.log(arr1);//=>[1]
    console.log(arr2);//=>[2,3,4]

参考资料

msdn
mdn

这个系列文章是我收纳、归纳、回顾前端基础知识。供自我与有需要的人,共同进步。感谢前人的分享,如有错处,请多提点

上一篇 下一篇

猜你喜欢

热点阅读