JavaScript Array Class

In this section, you will study how to use Array class in JavaScript.

JavaScript Array Class

In this section, you will study how to use Array class in JavaScript.

JavaScript Array Class

JavaScript Array Class

     

In this section, you will study how to use Array class in JavaScript. 

The Array class is one of the predefined classes available in JavaScript from which the object is to be derived. You can see in the given example where we have created an Array object. Syntax of creating an array object is ..

var colors = new array();

Then you can add the elements into it either by passing the string to the Array or by assigning  index number. While working  with an array, you'll find that it dynamically grows in size with each additional item. You can determine the size of Array by using length property.

Here is the codes

<html>
<head>
<h2>Use of Array Class</h2>
<script>
var colors = new Array();
colors[0] = "Red";
colors[1] = "Green";
colors[2] = "Blue";
colors[3] = "White";
colors[4] = "Black";
document.write("<b>The array is= </b>");
for(i=0;i<colors.length;i++)
document.write(colors[i]+",");
</script>
<body bgcolor="lightBlue"/>
</html>

Output will be displayed as:

Download Source Code