0

I am trying to get all Ids of the company Users and add it to the int array:

  userListIds: state.ddls.companyUsers.forEach(function (element) {
    ---How to add it to the int array
  });

Thanks in advance.

Irmantas Želionis
  • 2,032
  • 3
  • 15
  • 27
  • Possible duplicate of [From an array of objects, extract value of a property as array](https://stackoverflow.com/questions/19590865/from-an-array-of-objects-extract-value-of-a-property-as-array) – Heretic Monkey Jan 06 '19 at 19:42

2 Answers2

2

use map

 userListIds: state.ddls.companyUsers.map(function (element) {
     return element.id
  });
aseferov
  • 5,615
  • 3
  • 14
  • 20
1

It does the same from @aseferov but its written in ES6:

userListIds: state.ddls.companyUsers.map(element => element.id);
Serkan Sipahi
  • 641
  • 5
  • 16