I want to check if all value in the object are true, i want to return true if all are true but return false if any one is false
{
"2211284396232-5": {
"2211284396232-5": true,
"644889430161": {
"4812219518053": false,
"4812219518055": false,
"4812219518063": false,
"4812219518064": true,
"4812219518069": false,
"644889430161": false
},
},
"2211628865398-6": {
"2211628865398-6": false,
"729563966440": {
"5229922707373": false,
"729563966440": false
},
},
"2212485574058-4": {
"2212485574058-4": false,
"689399023594": {
"5077186698704": true,
"5077186698712": false,
"689399023594": false
},
},
}
I know of every()
method but my problem is the object are nested so i don’t know how to go about it. any help would be appreciated.
2
Answers
Write recursive tester. Loop all values and check if it’s boolean. If boolean – compare to true and return. If object – call itself once more.
What you can do is recursively flatten the object to an array of the values. Then you can call
every
on the result to test your result.