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