2D array in javascript

Sometimes in our web applications development we are in need of storing alot of data within one single variable, for this purpose we can use array.

However a Regular array can hold only one column (Such as names only or age only), but with 2D array we can store name and age within one single array.

so this is how javascript 2D array works...

<script type="text/javascript">


in our 2D Array we have two columns (Below)
0 = Name
1 = age

while a[n] displays how many ROWS we have


a = new Array()

a[0] = {0:"Saqib", 1:"27"} // Row 0 with Two columns (Name & Age)
a[1] = {0:"John", 1:"17"}  // Row 1 with Two columns (Name & Age)

alert(a[1][0]) // Row 1 & Column 0 ( Columns 0 = Name), it would return "John"


its pretty straight forward. as you can see you can create 3d or even 4d array easily if you want, just by changing the columns value.

any questions, please let me know.

 - Saqib


Posted by:

No comments posted.

Name :  

Email :  

Comment Below