javascript create array of objects from multiple arrays

Solutions on MaxInterview for javascript create array of objects from multiple arrays by the best coders in the world

showing results for - "javascript create array of objects from multiple arrays"
Maximilian
17 Jan 2017
1var ids = [1,2,3]; //Hundreds of elements here
2var names = ["john","doe","foo"]; //Hundreds of elements here
3var countries = ["AU","USA","USA"]; //Hundreds of elements here
4
5// Create the object array
6var items = ids.map((id, index) => {
7  return {
8    id: id,
9    name: names[index],
10    country: countries[index]
11  }
12});
13
14// Result
15var items = [
16    {id: 1, name: "john", country: "AU"},
17    {id: 2, name: "doe", country: "USA"},
18    ...
19];