JS Array Object

JavaScript Array Object

  • The Javascript Array object is a one-dimensional array that has several properties and methods.
    JavaScript stores lists of values in array.

Create JavaScript Array Object

Example 1:

<script type="text/javascript">
<!--
var cities=new Array(); 
 cities[0]="London";       
 cities[1]="New York";
 cities[2]="Toronto";
 cities[3]="Berlin";
 cities[4]="New Delhi";       
document.write(cities[2]); 
//-->
</script>

Result:

Toronto

Example 2:

<script type="text/javascript">
<!--
var cities=new Array("London", "New York", "Toronto", "Berlin", "New Delhi");        
document.write(cities[0]); 
//-->
</script>

Result:

London

Example 3:

<script type="text/javascript">
<!--
var cities=["London", "New York", "Toronto", "Berlin", "New Delhi"];        
document.write(cities[3]); 
//-->
</script>

Result:

Berlin