数组、去重、排序、合并、过滤、删除

内容分享5天前发布
0 0 0
  1. ES6数字去重
 Array.from(new Set([1,2,3,3,4,4])) //[1,2,3,4]   
  [...new Set([1,2,3,3,4,4])] //[1,2,3,4]

2、ES6数字排序

 [1,2,3,4].sort(); // [1, 2,3,4],默认是升序    
 [1,2,3,4].sort((a, b) => b - a); // [4,3,2,1] 降序

3、ES6数组合并

    [1,2,3,4].concat([5,6]) //[1,2,3,4,5,6]    
    [...[1,2,3,4],...[4,5]] //[1,2,3,4,5,6]    
    [1,2,3,4].push.apply([1,2,3,4],[5,6]) //[1,2,3,4,5,6]

4、ES6 过滤数组

[1,2,3].filter(item=>{return item>2}) //[3]

5:es6 数组删除

arr.splice(index, 1);
© 版权声明

相关文章

暂无评论

none
暂无评论...