isEmpty

isEmpty

> Functions

Determines whether the array array is empty. Equivalent to count(array) == 0.

Parameters
Return
TypeScript

In JavaScript, a.length === 0. The short form !a.length works too, but !a does not test emptiness: an empty array stays truthy, Boolean([]) is true, unlike in Python. And on a Map or a Set, it is size that must be read, not lengthlength is undefined there.

Python

In Python, not a is true for an empty list, and that is the idiomatic form. But it is also true for 0, "", None, an empty dictionary and an empty set: if the variable may not be a list, len(a) == 0 says exactly what isEmpty says.