-1

This is my response data:

var data = [{
                'name': 'ragu',
                'taxprice': '20'
            } {
                'name': 'ram',
                'taxprice': '20'
            } {
                'name': 'sandy',
                'taxprice': '20'
            } {
                'name': 'ramu',
                'taxprice': '20'
            }];

I want to add the all the taxprice value

my expected result is subtotal = 80

1
  • Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a minimal reproducible example of your attempt, noting input and expected output. Commented May 24, 2018 at 7:30

1 Answer 1

7

Use (Array.reduce)

var data = [{'name': 'ragu', 'taxprice': '20' }, {'name': 'ram', 'taxprice': '20'}, {'name': 'sandy', 'taxprice': '20'}, { 'name': 'ramu', 'taxprice': '20'}];
                
var result = data.reduce((a,c) => a + Number(c.taxprice), 0);
console.log(result);

Sign up to request clarification or add additional context in comments.

2 Comments

Many dupes here.
Agreed but with conversion to number may be hard to find. Hence, added the solution.