Tutorials » Javascript tutorials »

Array object


This article explains JavaScript Array object



Array


In simple words Array is collection of similar datatypes. Array index starts from 0.
Instead of declaring many variables for different strings or other data types, we can store it as a collection in an Array.

Defining an Array



Regular array


We declare array and assign in next statement.
var myArray = new Array(5)
Now in order to assign elements to Array

myArray[0]=”Hima”
myArray[1]=”Sandhya”
myArray[2]=”Sujatha”

Here length of the array is 5.

Condensed array


Here declaration and assignment can be done in a single statement

var myArray=new Array("Hima", "Sandhya", "Sujatha")

Literal array


Here we don’t use new key word to create an array. Directly we declare and assign. This is one type of declaring and assigning.

var myArray=["Hima", "Sandhya", "Sujatha"]

Index for Hima would be 0, String Sandhya is stored in 1st index and Sujatha is stored in 2nd position .

Now we can refer the element Sujatha as myArray[3]




Next Chapter: Array Object methods
Previous Chapter: JavaScript Date object's getYear()
More Chapters: Javascript Tutorials
More Tutorials: Tutorial Index



Top Contributors
Today
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    Gaurav Aroraa
    More...
     
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India