Answers for "how to get an array of unique objects from an object anfgular"

8

unique objects in array javascript

const array =
  [
    { "name": "Joe", "age": 17 },
    { "name": "Bob", "age": 17 },
    { "name": "Carl", "age": 35 }
  ]

const key = 'age';

const arrayUniqueByKey = [...new Map(array.map(item =>
  [item[key], item])).values()];

console.log(arrayUniqueByKey);

   /*OUTPUT
       [
        { "name": "Bob", "age": 17 },
        { "name": &quot
Posted by: Guest on September-14-2020

Code answers related to "how to get an array of unique objects from an object anfgular"

Code answers related to "Javascript"

Browse Popular Code Answers by Language