My code produces these two lines first:
1,2,3,4,5 1,2,3,4
Then it produces these lines, and those two disappear:
1,2,3 1,2 1
Why is this happening?
var arr=[1,2,3,4,5];
document.write(arr+"</br>");
function popit() {
if(arr.length>0) {
arr.pop();
if(arr.length<=0) {
clearTimeout(p);
document.write("end");
}
var p=setTimeout(popit,1000);
document.write(arr);
document.write("</br>");
}
}
window.onLoad=popit();