数组去重最简单的方法:ES6中Set方法
var array = new Set(['1','1','0','9'])
console.log(array) //{"1", "0", "9"}
console.log([...array]) //["1", "0", "9"]
js 判断数组对象中是否含有重复的值
比如说根据用户id判断
let arr = [
{id:1,name:2,age:3},
{id:2,name:3:age:24},
{id:1,name:5,age:6}
]
const ids = arr.map(value=>value.id);
const idsSet = new Set(ids);
if(idsSet.size() == ids.length){
console.log(“不存在同个值”)
}else{
console.log(“存在同个值”)