商品分類


JavaScript Array 降維展開

2021-10-07 06:11

搭配 reduce 做降維展開 (二維轉一維)

 

let arr = [
    [1, 2],
    [3, 4],
    [5, 6],
]

let concat = arr.reduce((previousValue, currentValue) => {
    return previousValue.concat(currentValue)
}, [])

console.log(concat)

購物車

購物車無商品
  • 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) }}
購物車