let arr = [1,2,3,4,5,6,7,8,9,8,7,6,4,5,3,2];
//利用set的特性去除重复值,再使用点语法转换成数组
arr = [...new Set(arr)];
console.log(arr);//[1,2,3,4,5,6,7,8,9]
js一行代码数组去重
最新推荐文章于 2024-07-04 14:34:42 发布
let arr = [1,2,3,4,5,6,7,8,9,8,7,6,4,5,3,2];
//利用set的特性去除重复值,再使用点语法转换成数组
arr = [...new Set(arr)];
console.log(arr);//[1,2,3,4,5,6,7,8,9]