Count particular key value from array of object Count particular key value from array of object angularjs angularjs

Count particular key value from array of object


Use Array#reduce method

var res = data.reduce(function(obj, v) {  // increment or set the property  // `(obj[v.status] || 0)` returns the property value if defined  // or 0 ( since `undefined` is a falsy value  obj[v.status] = (obj[v.status] || 0) + 1;  // return the updated object  return obj;  // set the initial value as an object}, {})