编程语言
首页 > 编程语言> > es6 数组的常用算法

es6 数组的常用算法

作者:互联网

es6 数组的常用算法

1.根据id删除指定元素,findIndex返回结果布尔值
this.prizes.splice(this.prizes.findIndex(e => e.id === this.prizeId), 1)
2.根据条件过滤数组元素,filter返回结果是数组
  this.radioList = res.data.filter(e=>e.channelEnableStatus !== 0)
3.es6数组方法find()、findIndex()与filter()的总结

https://www.jianshu.com/p/1c15be16a85a

4.根据数组里面数据的日期进行排序
arrData = arrData .sort((a,b)=>Date.parse(b.publishTime.replace(/-/g,"/"))-Date.parse(a.publishTime.replace(/-/g,"/")))

https://blog.csdn.net/qq_31561851/article/details/57130633

5.扩展运算扩展运算符和Set结构相结合,就可以去除数组的重复成员
let arr = [3, 5, 2, 2, 5, 5]; let unique = [...new Set(arr)]; // [3, 5, 2]

标签:es6,findIndex,parse,replace,filter,算法,数组
来源: https://www.cnblogs.com/U-ndefined/p/14452525.html