Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • 1
    \$\begingroup\$ Note that 0 in a and a[0] will fail for sparse arrays such as a = [,1,2]. Thus, !a.length is the most safe way to test for an empty array. When taking advantage of type casting to string, a==0 is another solution that directly returns a boolean value. \$\endgroup\$ Commented Sep 8, 2017 at 16:06
  • 2
    \$\begingroup\$ @TomasLangkaas but [0]==0 as well, so a==0 doesn't always work \$\endgroup\$ Commented Dec 19, 2021 at 21:27