📜  javascript 从多个数组创建对象数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:21.993000             🧑  作者: Mango

代码示例1
var ids = [1,2,3]; //Hundreds of elements here
var names = ["john","doe","foo"]; //Hundreds of elements here
var countries = ["AU","USA","USA"]; //Hundreds of elements here

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

// Result
var items = [
    {id: 1, name: "john", country: "AU"},
    {id: 2, name: "doe", country: "USA"},
    ...
];