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,194
  • 3
  • 17
  • 30
  • 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
  • 6,155
  • 3
  • 17
  • 24
1

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

userListIds: state.ddls.companyUsers.map(element => element.id);
Serkan Sipahi
  • 691
  • 6
  • 19