このコードの何が問題になっていますか?
var images = [];
function getImages() {
var st = true;
var i = 1;
var url;
var ob;
while(st) {
if(i < 10) {
url = "http://rachel-b.org/gallery/albums/Events/2012/May%2008%20-%20Rachel%20Bilson%20Celebrates%20Edie%20Rose%20Home%20Collection/thumb_00" + i + ".jpg";
ob = new Image();
ob.src = url;
st = checkIfImageExists(ob);
images.push(ob);
}
if(i >= 10 && i < 100) {
url = "http://rachel-b.org/gallery/albums/Events/2012/May%2008%20-%20Rachel%20Bilson%20Celebrates%20Edie%20Rose%20Home%20Collection/thumb_0" + i + ".jpg";
ob = new Image();
ob.src = url;
st = checkIfImageExists(ob);
images.push(ob);
}
if(i >= 100) {
url = "http://rachel-b.org/gallery/albums/Events/2012/May%2008%20-%20Rachel%20Bilson%20Celebrates%20Edie%20Rose%20Home%20Collection/thumb_" + i + ".jpg";
ob = new Image();
ob.src = url;
st = checkIfImageExists(ob);
images.push(ob);
}
i++;
}
}
function checkIfImageExists(o) {
var e = document.createElement("img");
e.style.display = "none";
document.getElementsByTagName("body")[0].appendChild(e);
e.src = o.src;
var res = e.width;
document.getElementsByTagName("body")[0].removeChild(e);
console.log(res);
if(res === 0) {
return false;
} else {
return true;
}
}
getImages();
function outPut() {
for(var i = 0; i < images.length; i++) {
console.log(images[i]);
}
}
outPut();
<ahref = "http://jsfiddle.net/rEA7k/7/" rel="nofollow">デモ
すべての配列要素を一度に出力しないのはなぜですか?同時に、実行ボタンを押すたびに、n+1個の配列要素が出力されます。どうして?