1

[Codepen Reactjs][1]

`https://codepen.io/sushil6263/pen/NJXQKo`

How to calculate the sum of all the value present in the state in the form of an array of object. and when we delete an item total amount value need to be a change

learner62
  • 520
  • 3
  • 10
  • 26

1 Answers1

0

Hope This helps

var accounts = [
      { name: 'James Brown', msgCount: 123 },
      { name: 'Stevie Wonder', msgCount: 22 },
      { name: 'Sly Stone', msgCount: 16 },
      { name: 'Otis Redding', msgCount: 300 }
    ];

// get sum of msgCount prop across all objects in array
var msgTotal = accounts.reduce((acc, cur) => (acc + cur.msgCount), 0);
Sumanth Madishetty
  • 3,425
  • 2
  • 12
  • 24