Home Java Javascript-array JavaScript Add Element to Array

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript Add Element to Array

Advertisement
In this section, you will learn how to add an element to Array. In the given example you can see that we have created an array object and added the elements by providing index number to the object.

JavaScript Add Element to Array

     

In the given JavaScript example, we have created an array object and then added the elements to it by providing index number to the object. This number starts from Zero (0) because whenever we assign any value to array it starts it's counting from 0 only. if an array is having the number 1(one) that means it is the second array in the given list of arrays.

So, while going through the example you will learn about how to add element to an array using JavaScript.

 

 

 

 

Here is the code:

<html>
<head>
<h2><u>Add Element to Array</u></h2>
<script>
var array = new Array();
array[0] = "Java";
array[1] = "ASP.NET";
array[2] = "JavaScript";
array[3] = "PERL";
array[4] = "C/C++";
document.write("<b>The Array is:</b> <br>");
for (i=0;i<array.length;i++)
{
document.write(array[i] + "<br >");

</script>
</head>
<body bgcolor="violet">
</html>

Output will be displayed as:

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 10, 2008

Related Tutorials

Discuss: JavaScript Add Element to Array  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
anirban
October 1, 2012
need help

how can i validate date confliction using java script? help with codeing example
DMCA.com