function jsonUnique(arr, attribute){
let new_arr = [];
let json_arr = [];
for(let i = 0; i < arr.length; i++){
if(new_arr.indexOf(arr[i][attribute]) == -1){
new_arr.push(arr[i][attribute]);
json_arr.push(arr[i]);
}
}
return json_arr;
}
console.log(jsonUnique([{a:1},{a:1},{a:2}], 'a'));
网友评论