Reputation: 2422
I have below object inside array
[
{
"age":32,
"test":true
},
{
"age":33,
"test":true
},
{
"age":35,
"test":false
}
]
I need to check if all values of test
is false
.
I have tried below code
Array.isArray(obj.map((message,index) => {
if(message.test !== message.test){
//trigger when all values are false
}
}))
How to achieve this?
Upvotes: 0
Views: 104
Reputation: 365
You can also you filter from array prototype...
const filtered = array.filter(a => a.test === true)
or the less verbose
const filtered = array.filter(a => a.test)
Upvotes: 0
Reputation: 49945
You can use every
from Array prototype:
let areAllFalse = array.every(x => x.test === false);
Upvotes: 7