I\'m getting an array returned to me and I need to count the rows that have a value in them
I\'ve tried to call arr.length but that gives me the total length of the
if you are a fan of Lodash, you can use countBy
(documentation)
const array = [{id:'1','':''},{id:'2','':''},{id:'3','':''},{id:'4','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''},{id:'','':''}]
// The iterator function `obj => obj.id === ''` returns Boolean value `true` or `false`
const count = _.countBy(array, obj => obj.id !== '');
// Get the `true` value
console.log(count.true);
One liner fans:
_.countBy(array, obj => obj.id !== '').true;