0👍
This is a good case for array.reduce. It would look something like this:
const totalRealizedPL => data.reduce(
(subtotal, item) => subtotal + item.realizedPL, // accumulator function
0 // initial value
);
// generate some data for demo purposes
const data = Array.from({length: 5}, () => ({ value: Math.floor(Math.random() * 100) }));
const sum = data.reduce((subtotal, item) => subtotal + item.value, 0);
console.log(sum);
console.log(data);
- [Vuejs]-GSAP ScrollTrigger triggering on mount, not on scroll
- [Vuejs]-Is it possible to style a menu differently on different "pages" in Vue.js?
Source:stackexchange.com