Adding elements to an array - Push()

by Sanju 2009-12-11 14:44:40

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

Tagged in:

1178
like
0
dislike
0
mail
flag

You must LOGIN to add comments