-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

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Please visit the [help], take the [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output. – mplungjan May 24 '18 at 07:30

1 Answers1

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);
Nikhil Aggarwal
  • 28,197
  • 4
  • 43
  • 59