How to create an array of objects from multiple arrays

You should be able to simply map through all ids, keeping a reference to your index, and build your object based on that index.

var items = ids.map((id, index) => {
  return {
    id: id,
    name: names[index],
    country: countries[index]
  }
});

Leave a Comment