When I use array.length != 0
to reference the condition of a non-empty array for a while loop, the rest of the code works fine. However, if I use array != []
to reference while an array is not empty, the same code gets TypeError (Cannot read properties of undefined) for the while loop.
I'm new to JavaScript. I thought either could mean the array is not empty, but apparently not. Can someone help explain the difference between array.length != 0
and array != []
? Thank you!!