es6之数组方法

//兼容插件 babel-polyfill

values()等存在兼容问题,需要加载babel-polyfill插件

.keys()  获取数组的key值

.values()  获取数组的value值

.entries() 获取key,value的值

.copyWithin(); 可传三个参数,第一个是指替换的位置,第二个只是替换的值开始的位置,第三个指替换的值结束的位置

 console.log([1,2,3,4,5].copyWithin(0,3,4))
//[4,2,3,4,5]

find查找第一个符合条件的数

//查找
    console.log([1,2,3,4,5,6].find(function(item){
        return item>3  //4
    }));
    console.log([1,2,3,4,5,6].findIndex(function(item){
        return item>3  //3
    }));

includes //查找具体的值

console.log("number",[1,2,NaN].includes(NaN)) //true

字符串转化成数组

Array.of

let arr=Array.of(3,4,7,9,11);
    console.log('arr=',arr);  //arr=[3, 4, 7, 9, 11]

 Array.from  将集合转化成数字、当有第二个参数时有map的功能 

  console.log(Array.from([1,3,5],function(item){
        return item*2;  //[2,6,10]
    }));

Array.fill() 填充数组的功能

console.log("fill-7",[1,"a",undefined].fill(7));  //[7,7,7]
console.log("fill-7",[1,"a",undefined].fill(7,1,3));  //[1,7,7]
fill 第一个参数是值被替换成的值,第二个参数是起始位置,第三个参数只是结束位置,不包括结束位置

    

posted @ 2017-11-20 12:23  karila  阅读(169)  评论(0编辑  收藏  举报