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:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: JavaScript Add Element to Array
Post your Comment