Skip to content
Advertisement

every() es6 for nested array is not working?

I expect true for below usage of every but it wasn’t, what’s wrong with my logic?

JavaScript

What I wanted: if any of the level 1 checked or nested checked is false then isAllChecked is false, but if non of the checked property in level 1 or nested is false, isAllChecked should return true.

Advertisement

Answer

Optional chaining will evaluate to undefined if the chain fails, so for the second iteration

JavaScript

will evaluate to

JavaScript

You probably wanted

JavaScript

or

JavaScript

JavaScript
Advertisement