If I have an object MyObject that contains an array of objects ListOfOtherObjects and I write this:
if (MyObject.ListOfOtherObjects.length !== 0) {...}
to test and see if the array contains OtherObjects, is it the same as writing this:
if (MyObject.ListOfOtherObjects) {...}
Thanks.
Nope, you need to check the
lengthproperty. AnArrayis always truthy, like any otherObject.You can, however, omit the explicit check of
!== 0.This condition will be
trueif theArrayhas at least one element.