[Vuejs]-Add multiple object values with the same key from object array using forEach in JavaScript

0๐Ÿ‘

getSubTotal(dataSet) {    
   return this.dataSet.map(function(data) {
     return data.price;
})

0๐Ÿ‘

Okay so I was able to figure this out.

dataSet: [
 {
 "price": 49,
 "qty": 1,
 },
 {
 "price": 29,
 "qty": 1,
 },
]

subTotals(data) {
  const calcArray = [data.price, data.qty];
  return calcArray.reduce((a,b)=> {
    //multiply price by quantity for subtotal
    return a*b;
  });
}

Leave a comment