📜  JavaScript 展平数组 - Javascript 代码示例

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

代码示例2
const arr = [1, 2, [3, 4]];

// To flat single level array
arr.flat();
// is equivalent to
arr.reduce((acc, val) => acc.concat(val), []);
// [1, 2, 3, 4]

// or with decomposition syntax
const flattened = arr => [].concat(...arr);