I have a loop like the following:
for (var i = 0; i < arr.length; i++) {
console.log(arr);
// rest of the code does not touch 'arr'
...
}
However, in the browser console (Chrome), I keep getting this:
Array[0]
length: 0
__proto__: Array[0]
as the output of console.log(arr), which suggests that there is nothing in arr. But then how is it possible that the logging statement gets executed?!
arrthen? Is it empty or not?iis zero andarr.lengthis zero theni < arr.lengthisfalseand it will not enter your loop. So arr is not of zero length.