Array in JavaScript


Array in JavaScript


Array are collection of data items stored under a single name. Array provide a mechanism for declaring and accessing several data items with only one identifier, thereby simplifying the task of data management.

We use array when we have to deal with multiple data items.
Arrays are a special type of objects. The type of operator in JavaScript returns "Object" for arrays.

How Array Stores Value ?

Here in this array it stores values as roll numbers, it starts values from 0 1 2 meanwhile it says not a roll numbers , it says index .

                      0   1   2              ---    index
Ex : var ary = [10,20,30] ;

        document.write(ary);       --     it shows entire value

if you want to show specific value in array , you have to define index values like this ..

    
    document.write(ary[0]) ;   --     0 is starting of the index value
                                                          you can define the index values.

   
    var array = ['one','two','three'];
        document.write(array);

array[] with index value::

          var array = ['one','two','three'];
        document.write(array[0]);


array[] with data types 


        var array = [100"ramesh"truenull ];
        document.write(array);
        


For loop in array 


by using this loop you can show the array values in vertically , here is the example to show the array values ..

Ex: 

                var ary = [10,20,30,40,50];

        for (var a=0a <= 4a++){
                document.write(ary[a] + "<br>");
        }