Pop() to remove last element of an array

by Sanju 2009-12-11 14:31:32

Pop() to remove last element of an array

We can remove the last element of the array by applying pop() method to the JavaScript function.

Here is the syntax of applying pop() method to an array

Syntax:
scripts.pop();


Example:

<script type="text/javascript">
var scripts = new Array();
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>");
scripts.pop();
document.write(scripts.join(" <br> "));

</script>


Result:

Domain
Hosting
FreeTemplates
JAvascript
--Now after applying pop()--
Domain
Hosting
FreeTemplates


Tagged in:

1364
like
0
dislike
0
mail
flag

You must LOGIN to add comments