Take a look at the JavaScript code snippet below:
var words = delIdx = [0, 1, 2, 3];
for(let i=0; delIdx[i]; i++) {
console.log('DELIDX: ', delIdx[i]);
}
for(let i=0; words[i]; i++) {
console.log('Word: ', words[i]);
}
The arrays words
and delIdx
are being used in the FOR loops to control the execution of the code. However, when the first element of the array is set to 0, the loops do not work as expected and do not enter the loop at all.
Changing the array's values to
var words = delIdx = [2, 3, 4, 5]
resolves the issue and the loops work correctly.
Have you encountered this problem before? Is it a bug in JavaScript?
This behavior was observed in Node.js v5.3.0 and FireFox 44.0.2 console.
Any thoughts or insights on this?
Thank you.