0

suppose with we have an array of objects like this: array = [{side:1, value:2}, {side:1, value:3}, {side:2, value:4}, {side:2, value: 4}, {side:3, value:3}] I want to create an array which contains only the side attibute without duplications like this: sideArray = [1,2,3]. These are the values of the side. How to do this?

RamAlx
  • 6,976
  • 23
  • 58
  • 106
  • I think that will help you http://stackoverflow.com/questions/921789/how-to-loop-through-plain-javascript-object-with-objects-as-members :) –  May 15 '17 at 17:13

1 Answers1

1

You can use map() method to return array with side values and then Set and spread syntax to remove duplicates.

var array = [{side:1, value:2}, {side:1, value:3}, {side:2, value:4}, {side:2, value: 4}, {side:3, value:3}]

var result = [...new Set(array.map(e => e.side))];
console.log(result)
Nenad Vracar
  • 118,580
  • 15
  • 151
  • 176