I have the following javascript array of objects ,I need to check output property if at least one object is true return true else return false,Can anyone help me to implement that?
var array=[{"id":100,"output":false},{"id":100,"output":false},
{"id":100,"output":true}]
You could use Array#some
The
some()
method tests whether some element in the array passes the test implemented by the provided function.
var array = [{ "id": 100, "output": false }, { "id": 100, "output": false }, { "id": 100, "output": true }];
result = array.some(function (a) { return a.output; });
console.log(result);
function hasOneTrue(a){
return !!a.filter(function(v){
return v.output;
}).length;
}
var array = [{"id":100,"output":false}, {"id":100,"output":false}, {"id":100,"output":true}]
console.log(hasOneTrue(array)); // true
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