An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).
(i) Empty Array:- that array has not value is called Empty Array.Empty Array always return, undefine value.
<script> var myarr=[]; document.write(myarr[0]); //Output:- undefined </script>
(ii) Array of strings:- In the below eg. array has 3 string values. array index start 0.
<script> var myarr=["John","Tony","Alix"]; document.write(myarr[0]); //Output:- John document.write(myarr[1]); //Output:- Tony document.write(myarr[2]); //Output:- Alix </script>
(iii) Array of Numbers:- In the below eg. array has 3 number values.
<script> var myarr=[11,12,13]; document.write(myarr[0]); //Output:- 11 document.write(myarr[1]); //Output:- 12 document.write(myarr[2]); //Output:- 13 </script>
(iv) Array of Booleans :- In the below eg. array has 3 boolean values.
<script> var myarr=[true,false,true]; document.write(myarr[0]); //Output:- true document.write(myarr[1]); //Output:- false document.write(myarr[2]); //Output:- true </script>
(v) Array of Array :- In the below eg. array has 2 array.
<script>var myarr=[ ["a","b","c"],["x","y","z"] ]; document.write(myarr[0][0]); //Output:- a document.write(myarr[0][1]); //Output:- b document.write(myarr[0][2]); //Output:- c document.write(myarr[1][0]); //Output:- x document.write(myarr[1][1]); //Output:- y document.write(myarr[1][2]); //Output:- z </script>
(vi) Array of Objects:- In the below eg. array has 2 object values.
<script> var myarr_data = [ {}, {}, {}, {}, {} ]; myarr=[{name:"john",age:27},{name:"tony",age:28}] document.write(myarr[0].name); //Output:- john document.write(myarr[0].age); //Output:- 27 document.write(myarr[1].name); //Output:- tony document.write(myarr[1].age); //Output:- 28 </script>
(vii) Array with Mixed Data Types:-
<script> var myarr_data = [ {}, "text",11,null,true,[] ]; </script>