An array disappears in "for" expression, <p>There's some code, and it's not working. </p> <pre><code>window.onload = function () { var div = document.getElementById ('main'); var img = div.children; var i = 1; //console.log(img[i]); for (var i=1; i != img.length; i++) { img[i].onclick = function () { console.log(img[i]); } } } </code></pre> <p>Please, explain me Why is img[i] in <code>console.log(img[i]);</code> undefined ? How this bug can be fixed?</p>