0 points

get list of unique items from a list of objects with duplicate objects


dashboard

Mon Nov 02 2020 19:26:40 GMT+0000 (UTC)

Posted by @ali_alaraby #javascript

// filterProperty i.e. 'id' or 'name'
function GetUniqueItems(array, filterProperty) {
	return array
    .map(e => e['filterProperty'])
    .map((e, i, final) => final.indexOf(e) === i && i)
    .filter(obj=> array[obj])
    .map(e => array[e]);
}
content_copy Copy