function init (arr) {
var newArr = [];
if (arr instanceof Array) {
arr.forEach(function (value) {
newArr = newArr.concat(init(value));
});
} else {
newArr.push(arr);
}
return newArr;
}
init([1, [2], [3, [[4]]]]);
多维数组扁平化
最新推荐文章于 2023-10-12 16:44:33 发布