I have array of different objects which look like this:
[{
color:'red',
'type':'2',
'status':'true'
}
{
color:'red',
'type':'2',
'status':'false'
}]
I want to filter the one element like status
and then count the filtered, for example if status is false then return 1.
I have tried the below code but I am not sure what I am doing here:
for (i = 0; i < check.length; i++) {
var check2;
console.log(check[i].isApproved);
(function(check2) {
return check2 = check.filter(function(val) {
return val == false
}).length;
})(check2)
console.log('again Rides',check2);
}
If I understood correctly you want to count the number of elements where status
is equal to 'false'
note: The values you have in status
are strings
var check = [
{ color:'red', 'type':'2', 'status':'true' },
{ color:'red', 'type':'2', 'status':'false' }
];
var countfiltered = check.filter(function(element){
return element.status == 'false';
}).length
console.log(countfiltered);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With