Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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 by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #map #return #array #distinc #values
ADD COMMENT
Topic
Name
3+2 =