商品分類


JavaScript 陣列合併

2021-10-07 10:18

使用方式

newArray = currentArray.concat(value1, value2, ...)
newArray 合併後的新陣列
currentArray 目前陣列
value 可以是單一值或是一個陣列

 

單一值合併

let currentArray = [1, 2, 3, 4, 5]
let newArray = currentArray.concat(99)
console.log(newArray)
// (6) [1, 2, 3, 4, 5, 99]

 

陣列合併

let currentArray = [1, 2, 3, 4, 5]
let someArray = ['Hi', 'David', 888]
let newArray = currentArray.concat(someArray)
console.log(newArray)
// (8) [1, 2, 3, 4, 5, "Hi", "David", 888]

購物車

購物車無商品
  • NT$ {{ Utils . numberWithCommas(item . product . price) }} x {{ item . qty }} = NT$ {{ Utils . numberWithCommas(item . product . price * item . qty) }}
小計:
NT$ {{ Utils . numberWithCommas(cart . subtotal) }}
總計:
NT$ {{ Utils . numberWithCommas(cart . total) }}
購物車