es6中新增了set类型的数据,自动去掉重复的数据
let arr=[1,2,3,1,2,4,3,3,5];
console.log(new Set(arr)) //你会发现输出的已经去重了,但是,返回的是个对象,需要用到Array.from()

Array.from()的作用是是可以把类数组对象转化为数组。

es6中新增了set类型的数据,自动去掉重复的数据
let arr=[1,2,3,1,2,4,3,3,5];
console.log(new Set(arr)) //你会发现输出的已经去重了,但是,返回的是个对象,需要用到Array.from()
Array.from()的作用是是可以把类数组对象转化为数组。
本文标题:ES6去重
本文链接:https://www.haomeiwen.com/subject/errmittx.html
网友评论