Follow in Twitter & Facebook


Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools


Friday, September 7, 2012

JavaScript array tutorial

In this article we will see how to define and use an array in JavaScript. Also you can check my last article on how to enable javascript in different browser here. Also you can check some jQuery articles.

To define an array in javascript we can use the keyword var like below:

var arr = new Array();  // Here the size is not defined.

var arr = new Array(3); // Here the array size is defined to 3

Below is the way to add items to the array.

var arr = new Array(3);

arr[0] ="SharePointDotNet.com";
arr[1] ="EnjoySharePoint.com";

arr[2] = "Fewlines4Biju.com";

Remember the array index always starts from 0.

You can also directly define and assign elements to an array like below:

var arr = new Array ("SharePointDotNet.com","EnjoySharePoint.com","Fewlines4Biju.com");

Similarly to retrive value from an array with index like below.

alert ( arr[0] ) : It will return the value which is present in the zeroth index.

Also you can check an article on how to convert an arraylist to string.




0 on: "JavaScript array tutorial"