And you'd like to remove duplicates from this array, but not looking just for the unique objects as a whole, but unique properties of objects. So for example, you'd like to remove duplicates based on 'id' property of each object in the Array.

So this can be done in many ways, one of the ways I wrote today is rather brief, here is how it goes.

We use Array.filter(). Array.filter accepts up to 3 arguments.

1. Current array item being filtered.2. Index of this item.3. The full array we are filtering.

So we could do something like:

let filtered = p.filter((item, index, array) => {
let array_ids = array.map(item => item.id); // to get an array of just the ids, or whichever property we'd like to filter with.
if(array_ids.indexOf(item.id) === index) {
return true; // if we return true inside Array.filter(), that item is included in the resultant array.
} else {
return false; // otherwise it is not included. Returning false will omit the current item being checked.
}
});

We can improve this a little bit better by writing it in one line like: