使用new Set()快速数组去重:
let arr = [1, 2, 2, 3, 4, 5, 5, 5, 6] let set = new Set([...arr]) console.log([...set]) //[1, 2, 3, 4, 5, 6] function SetArr(array) { return Array.from(new Set(array)); } console.log(SetArr([1, 1, 2, 2, 3, 4, 4])) // [1, 2, 3,4]
原文地址:https://www.cnblogs.com/lwming/p/11123461.html
时间: 2024-11-08 23:12:31