我必须在 Angularjs 中将数组 block 合并为单个数组和对象数组。
我的输入数组将是这样的:
[
[
{
"title": "asd",
"description": "asd"
},
{
"title": "asz",
"description": "sd"
}
],
[
{
"title": "ws",
"description": "sd"
},
{
"title": "re",
"description": "sd"
}
],
[
{
"title": "32",
"description": "xxs"
},
{
"title": "xxc",
"description": "11"
}
]
]
上面的输入数组应该像下面的对象数组一样保存
[
{
"title": "asd",
"description": "asd"
},
{
"title": "asz",
"description": "sd"
},
{
"title": "ws",
"description": "sd"
},
{
"title": "re",
"description": "sd"
},
{
"title": "32",
"description": "xxs"
},
{
"title": "xxc",
"description": "11"
}
]
请建议我如何实现这一目标。
提前致谢
最佳答案
let data = [[{"title": "asd","description": "asd"},{"title": "asz","description": "sd"}],[{"title": "ws","description": "sd"},{"title": "re","description": "sd"}],[{"title": "32","description": "xxs"},{"title": "xxc","description": "11"}]];
let result = data.reduce((a, c) => a.concat(c), []);
console.log(result);
关于javascript - 将数组对象 block 合并到单个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50618091/