Skip to content Skip to sidebar Skip to footer

How To Get A List Of Objects By Their Id Using An Array Of Numbers

NOTE: I understand that the title is phrased ambiguously and the explanation below is simplistic, apologies I'm a little new to JS I have this array of objects (this.listOfAnimals)

Solution 1:

Use map() to iterate over arrayOfNumbers, and use the values as indexes into listOfAnimals

let selectedAnimals = this.arrayOfNumbers.map(n => this.listOfAnimals[n]);

Solution 2:


Post a Comment for "How To Get A List Of Objects By Their Id Using An Array Of Numbers"