鍍金池/ 問答/HTML/ 有這樣一個多維數(shù)組,獲取每個子數(shù)組中index為1的值,算出所有值的總和

有這樣一個多維數(shù)組,獲取每個子數(shù)組中index為1的值,算出所有值的總和

我使用循環(huán)遍歷算出來了,但是感覺代碼太多,不知道es6 有沒有更好的計算方式

var array = [
    ["18.8000", "10.0000"]
    ["20.0000", "10.0000"]
    ["20.1000", "10.0000"]
    ["20.2000", "1370"]
    ["20.6000", "2120"]
    ["20.9000", "1480"]
]
let total = 0;
  for (let index = 0; index < array .length; index++) {
    const element = +array[index][1];
    total += element;
  }
  console.log(total);
回答
編輯回答
你好胸

array.reduce(function(sum,item){return sum += +item[1] },0)

2018年7月1日 18:29