Here you can find a number of examples on Java Script.Please find the various kinds of examples listed on the right side of this site. If you don't find anything on Java Script then please write to us or leave a commnet. We are pleased to help and find the solution of your problem.
Showing posts with label push function. Show all posts
Showing posts with label push function. Show all posts

JavaScript: Push Function



Push Function:
Adds one or more elements to the end of an array and returns the last element added to the array. This method changes the length of the array.

Syntax:
arrayname.push("element1","element2",.......,"elementN")

Description:
The behavior of the push method is analogous to the push function in Perl 4. Note that this behavior is different in Perl 5.


Example in HEAD Section:

<html>
<head>
<title>Push Function</title>
<script language="javascript">
myfish=new Array("Elephent", "Lion" , "Tiger" , "Cat" , "Dog");
document.write("<b>Before my Array is:</b> " +myfish +"<br>");
document.write("<b>Total element in the Array is:</b> " + myfish1.push("Mouse"));
document.write("<br><b>After my Array is:</b> " +myfish);
</script>
</head>
</html>


Example in BODY Section:

<html>
<head>
<title>Push Function</title>
</head>
<body>
<script language="javascript">
myfish=new Array("Elephent", "Lion" , "Tiger" , "Cat" , "Dog");
document.write("<b>Before my Array is:</b> " +myfish +"<br>");
document.write("<b>Total element in the Array is:</b> " + myfish1.push("Mouse"));
document.write("<br><b>After my Array is:</b> " +myfish);
</script>
</body>
</html>



OUTPUT:

Before my Array is: Elephent,Lion,Tiger,Cat,Dog
Total element in the Array is: 6
After my Array is: Elephent,Lion,Tiger,Cat,Dog,Mouse
Google