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 body. Show all posts
Showing posts with label body. Show all posts

JavaScript: POP Function



pop Function:
Removes the last element from an array and returns that element. This method changes the length of the array.

Syntax:
arrayname.pop()


Example in HEAD Section:

<html>
<head>
<title>pop function</title>
<script language="javascript">
myfish = ["Onion", "Bannana"," Orange", "Apple"];
document.write("<b>Before my Array is:</b> " + myfish +"<br>");
document.write("<b>Remove element in the array is:</b> " + myfish.pop());
document.write("<br><b>After my Array is:</b> " + myfish);
</script>
</head>
</html>


Example in BODY Section:

<html>
<head>
<title>pop function</title>
</head>
<body>
<script language="javascript">
myfish = ["Onion", "Bannana"," Orange", "Apple"];
document.write("<b>Before my Array is:</b> " + myfish +"<br>");
document.write("<b>Remove element in the array is:</b> " + myfish.pop());
document.write("<br><b>After my Array is:</b> " + myfish);
</script>
</body>
</html>



OUTPUT:

Before my Array is: Onion,Bannana,Orange,Apple
Remove element in the array is: Apple
After my Array is: Onion,Bannana,Orange

JavaScript: Random Function



random function:
Returns a pseudo-random number between 0 and 1. The random number generator is seeded from the current time, as in Java.

Syntax:
random()

Description:
Because random is a static method of Math, you always use it as Math.random(), rather than as a method of a Math object you created.



Example in HEAD section:

<html>
<head>
<title>Random Function</title>
<script language="javascript">
document.write(Math.random(1));
</script>
</head>
</html>


Example in BODY section:

<html>
<head>
<title>Random Function</title>
</head>
<body>
<script language="javascript">
document.write(Math.random(1));
</script>
</body>
</html>




OUTPUT

0.7415897142562586
Google