gpt4 book ai didi

javascript - 如何在 javascript 中展平嵌套数组?

转载 作者:IT王子 更新时间:2023-10-29 03:17:42 27 4
gpt4 key购买 nike

<分区>

正如我们所知,通过使用方法 reduce() 来展平数组 [[0, 1], [2, 3], [4, 5]] >

var flattened = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
return a.concat(b);
});

那么如何将数组 [[[0], [1]], [[2], [3]], [[4], [5]]] 展平为 [0, 1, 2, 3, 4, 5]?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com