...

View Full Version : for loop array wont alert?



andrew1234
07-18-2009, 11:48 AM
Hi

Thanks for the help.

if I put alert(Images[i]); in the for loop then it alerts all images 1 to 6

but if I put alert](Images3); out site it ignores the alert?

Why..... surly all these images1 to 6 should be there?

Thanks

for the help

A





for(var i=1;i<=6;i++){

var Images = new Array()

Images[i] = "images/no"+i+".jpg";

}

alert(Images3);

venegal
07-18-2009, 12:21 PM
alert(Images3); is being ignored because the variable Images3 is not defined. You probably mean Images[3].

andrew1234
07-18-2009, 12:39 PM
Hi Thanks for the reply


i added Images[3]

now it says images3 undefined?

Any ideas of how to define it?

thanks for the help

venegal
07-18-2009, 12:45 PM
Why would it say images3 is undefined? Unless you're holding out on me, images3 isn't even mentioned in your code. There has been Images3, but you just changed that to Images[3], right?

Post some code or I'm afraid I won't be able to help you.

A1ien51
07-18-2009, 01:34 PM
Sounds like you are cached if you make a change and you re not seeing it. Clear it. :)

Eric

barkermn01
07-18-2009, 03:03 PM
for(var i=1;i<=6;i++){

var Images = new Array()

Images[i] = "images/no"+i+".jpg";

}

alert(Images3);

Every time your looping your clearing the array it shoudl be


var Images = [] // new array is only to defind max entryed E.G "new Array(100);" [] set a no limit array
for(var i = 1; i <= 6 ; i++){
Images[i] = "images/no"+i+".jpg";
}

alert(Images[3]);

andrew1234
07-18-2009, 04:49 PM
thanks for the help

that makes so much sense.....

barkermn01
07-18-2009, 07:36 PM
I Would, like to say that why has a Senior Coder, not noticed this???

But i dont want to flame or start a flame but people should read code porperly befor answering

Philip M
07-18-2009, 08:04 PM
There are none so blind as those that cannot see. :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum