-1

Inside the for loop I m getting this data

This values getting from EXT js store.

  var sum = results.rows.item(i).Count;
  console.log(sum);

in the result, it showing

2

5

6

3

I need a total count of this sum in a single variable. Anybody can answer this, please. It's a javascript function.

sarathi
  • 1,009
  • 1
  • 7
  • 14

2 Answers2

2

You can use the reduce function for that:

let array = [2,5,6,3];


// will reduce an array to a single variable.
let sum = array.reduce((collector, num) => {
  // the collector is kept for each iteration
  return collector += num;
}, 0 /* initial value is 0 */);

console.log(sum)
Nicolas
  • 8,077
  • 4
  • 21
  • 51
0

just use ExtJS's inbuilt function on the store object:

myStore.sum('items'); // assuming 'items' is the field you need to sum

https://docs.sencha.com/extjs/7.0.0/classic/Ext.data.Store.html#method-sum

if it's a grouped store you can also get sum of group.

Dawesi
  • 568
  • 3
  • 9