Irmantas Želionis
Irmantas Želionis

Reputation: 2324

Get specific attribute from array of objects?

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.

Upvotes: 0

Views: 30

Answers (2)

Serkan Sipahi
Serkan Sipahi

Reputation: 691

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

userListIds: state.ddls.companyUsers.map(element => element.id);

Upvotes: 1

aseferov
aseferov

Reputation: 6393

use map

 userListIds: state.ddls.companyUsers.map(function (element) {
     return element.id
  });

Upvotes: 2

Related Questions