August 16, 2009

Javascript Tutorial 6: Changing And Adding Array Elements

var names= new Array();
names[0]="first";
names[1]="second";
names[2]="third";
alert (names[2]);


Now let's experiment with this:


names[0]="first";
names[1]="second";
names[2]="third";
alert (names[2]);

names[2]="fourth";
alert (names[2]);


This would display both words in popup but in two different ones labeled "names 2".

You can also declare varibles in array after it is used (does not matter how many times). Just continue the line like

names[3]="fifth";
And then you can use it in an alert box again.

alert (names[3]);

Alert box will display the first defined alert with message from variable names[2] and then from names[3].

Technorati Tags: , ,

No comments:

Post a Comment