August 15, 2009

Javascript 5: Arrays

var names=new Array("test","once","twice");
Each of the quotated are each of the message saved to the variable. The word Array has to be capitalized. This variable "names" have three variables test, once, twice.
Now like before:
alert (names[1]);
Picks the second of the variable array list. Computer starts counting from zero.

Second Way to Declare Array
var names= new Array();
names[0]="test";
names[1]="once";
names[2]="twice";

Now Alert it:

alert(names[2]);

This would return you with the "twice" in the alert box.

Technorati Tags: , , ,

No comments:

Post a Comment