DEV Community

Nagarajan R
Nagarajan R

Posted on

Answer: Create array of unique objects by property

Shortest, but not best performance (see update bellow) solution for es6 :

function unique(array, propertyName) {
   return array.filter((e, i) => array.findIndex(a => a[propertyName] === e[propertyName]) === i);
}

performance: https://jsperf.com/compare-unique-array-by-property

Top comments (0)