[Vuejs]-Calculations inside of loop and how to return sum of values . Vuejs

3👍

it sounds like you should use a reduce

const total = this.equities.reduce((sum, equity) => {
  const myEquityCalc = << something >>;
  return sum + myEquityCalc;
}, 0)

Demo:

const equities = [{value: 100}, {value: 200}];

const total = equities.reduce((sum, equity) => {
  return sum + equity.value;
}, 0)

console.log(total)

Leave a comment