Reputation: 51937
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.
Upvotes: 0
Views: 423
Reputation: 490233
Nope, you need to check the length
property. An Array
is always truthy, like any other Object
.
You can, however, omit the explicit check of !== 0
.
if (MyObject.ListOfOtherObjects.length) {...}
This condition will be true
if the Array
has at least one element.
Upvotes: 5