usereduce
The array_object () method is used to decrement an array object
function unique(uniqueArr) {
var has = {};
return uniqueArr.reduce(function (arr, item) {
!has[item.id] && (has[item.id] = true && arr.push(item));
returnarr; } []); }var arr = [
{
id: 'P001'.name: 1}, {id: 'P002'.name: 2}, {id: 'P001'.name: 1,},];Call * / / *
console.log(unique(arr))
Copy the code