JavaScript将二维数组转为一维数组

使用ES6的扩展运算符——“···”
let nums = [[1, 2], [3, 4]];
let arr = [];
for (let item of nums) {
    
    
    arr.push(...item);
}
console.log(arr); 	//[1, 2, 3, 4]

猜你喜欢

转载自blog.csdn.net/weixin_43757001/article/details/108439033