我对使用reduce有点困惑。
它的用法是array.reduce((accumulator, value) => 对accumulator进行一些操作,但为什么会返回一个空数组呢?
let a = [
[1,2],
[
[3,4]
],
[
[[5],[6]]
]
];
const flatten = arr => arr.reduce((a, v) => {
v instanceof Array ? flatten(v) : a.push(v);
return a;
}, [])
console.log(flatten(a));
Array.prototype.flat()
或Array.prototype.flatMap()
为什么没有被使用? - guest271314