set数组去重
new Set

const arr = [{name:"wo"},{name:"shi"},{name:"wo"}]
console.log([...new Set(arr.map(item=>item.name))].length)//2
if([...new Set(arr.map(item=>item.name))].length < arr.length){
let arr2 = [...new Set(arr.map(item=>item.name))]
console.log(arr2)//["wo", "shi"]
}
文献:
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Set
只有在泥泞的道路上才能留下脚印

浙公网安备 33010602011771号