Using es6 spread to concat multiple arrays

前端 未结 8 1232
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 14:50

We all know you can do:

let arr1 = [1,2,3];
let arr2 = [3,4,5];
let arr3 = [...arr1, ...arr2]; // [1,2,3,3,4,5]

But how do you make this dynami

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 15:25

    let fruits = ["apples", "bananas", "pears"];
    let vegetables = ["corn", "potatoes", "carrots"];
    
    let produce = [...fruits, ...vegetables];
    
    
    console.log(produce);

提交回复
热议问题