close
ES6後 很方便的寫法 把陣列前面加上三個點 ex ...array 就等於展開裡面的資料 用以下例子來示範
const firstArray = [1, 2, 3];
const firstArray2 = [...firstArray];
const newFirstArray = [4,...firstArray,5];
console.log(...firstArray);
//1 2 3
console.log(firstArray2);
//[1,2,3]
console.log(newFirstArray);
//[4,1,2,3,5]
slice() 括弧內不給值或是給0都可以當成簡易的複製陣列
const newArray = firstArray.slice();
console.log(newArray);
//[1,2,3]
文章標籤
全站熱搜