const arrays = [
[123, "string1"],
[4564564, "string2"],
[392341231, "string3"],
[1665342, "String4", 334934543, "string5"]
];
const s = arrays.reduce((acc, val) => {
return acc.concat(val);
});
// output:
// [123, "string1", 4564564, "string2", 392341231, "string3", 1665342, "String4", 334934543, "string5"]
扁平化阵列后,输出的是一个number一个string的,我尝试使用reduce,使物体像
{
123: "string1",
4564564: "string2",
392341231: "string3",
1665342: "String4",
334934543: "string5"
}
.reduce(function(acc, cur, i) {
acc[cur] = cur;
return acc;
}, {});
输出错误,如何分离number和string内部reduce?谢谢
元芳怎么了
红糖糍粑
翻过高山走不出你
相关分类