这里我在数组中有一个JSON对象,并将其推送到employeeArray,即
employeeArray =[
[
{
"ID":"967",
"NAME":"Dang, Lance D",
"Email":"Lance.Dang@xyz.com"
}
],
[
{
"ID":"450",
"NAME":"Starnes, Mitch",
"Email":"Mitchell.Starnes@xyz.com"
}
],
[
{
"ID":"499",
"NAME":"Cosby, Lance H",
"Email":"Lance.Cosby@xyz.com"
}
]
];
如何将这个带到像这样的JSON对象的单个数组中
employeeArray =[
{
"ID":"967",
"NAME":"Dang, Lance D",
"Email":"Lance.Dang@xyz.com"
},
{
"ID":"450",
"NAME":"Starnes, Mitch",
"Email":"Mitchell.Starnes@xyz.com"
},
{
"ID":"499",
"NAME":"Cosby, Lance H",
"Email":"Lance.Cosby@xyz.com"
}
];
帮助我如何使用上面的二维数组值并在纯javascript中构建我期望的数组
答案 0 :(得分:3)
您希望展平数组,可以通过reduce
调用来完成:
employeeArray.reduce((p, c) => p.concat(c), [])
ES5:
employeeArray.reduce(function (p, c) {
return p.concat(c);
}, []);