用集合+扩展运算符实现数组去重

let arr = [1, 1, 2, 2, 3, 4, 5];
let res = new Set(arr);
console.log(res);  //{1, 2, 3, 4, 5}
let arr1 = [...res];
console.log(arr1);  //[1, 2, 3, 4, 5]

posted on 2021-08-07 19:11  In-6026  阅读(98)  评论(0)    收藏  举报

导航