Adding elements to an array - Push() - Javascript Views : 458
Tagged in : Javascript
0 0
Send mail
Adding elements to an array - Push()

We can add new element at the end of the array by using push() method to the Javascript function.

Here is the syntax to add elements to an array.

scripts.push("Windows","Linux");


Example:

<script type="text/javascript">
scripts[0] = "Domain";
scripts[1] = "Hosting";
scripts[2] = "FreeTemplates";
scripts[3] = "Javascript";
document.write(scripts.join(" <br> "));
document.write("<br>--Now after applying pop()--<br>
push("Windows","Linux");
document.write(scripts.join(" <br> "));



Result:

Domain
Hosting
FreeTemplates
Javascript
--Now after applying push()--
Domain
Hosting
FreeTemplates
Javascript
Windows
Linux

By Sanju, On - 2009-12-11



    Login to add Comments .