codingtcher.com
Theme Night
Home
Login

javascript distinct object array

Home » Tutorial Post » javascript distinct object array

javascript map return array with distinc values

//ES6
let array = [
  { "name": "Joe", "age": 17 },
  { "name": "Bob", "age": 17 },
  { "name": "Carl", "age": 35 }
];
array.map(item => item.age)
  .filter((value, index, self) => self.indexOf(value) === index)

> [17, 35]
Source: stackoverflow.com

javascript get unique values from key

const unique = [...new Set(array.map(item => item.age))];
Source: stackoverflow.com

Related Post