标签:var for ++ next console pwd reduce key function
// 使用数组方法reduce去重
var obj = {};
var aa = [{
"name": "aa",
"pwd": "xvxv"
}, {
"name": "aa",
"pwd": "xvxv"
}, {
"name": "bb",
"pwd": "xvxv"
}, {
"name": "cc",
"pwd": "xvxv"
}];
aa = aa.reduce(function(item, next) {
obj[next.name] ? ‘‘ : obj[next.name] = true && item.push(next);
return item;
}, []);
console.log(aa);
// 判断对象中是否存在key
var result = [];
var obj = {};
for(var i =0; i<aa.length; i++){
if(!obj[aa[i].key]){
result.push(aa[i]);
obj[aa[i].key] = true;
}
}
console.log(result);
// 纯数组去重
var arr = [1,2,3,1,2,3,4];
var arr_later = [];
arr.forEach((item,index)=>{
if(index == arr.indexOf(item)){
arr_later.push(item);
}
)
console.log(arr_later);
标签:var for ++ next console pwd reduce key function
原文地址:https://www.cnblogs.com/lfnumber7/p/13150673.html