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

JavaScript: splice Function



Splice Function:
Changes the content of an array,adding new elements while removing old elements.

Syntax:
splice(index,howmany,"element1","element2",......,"elementN");

Parameters:
index:Index at which to start changing the array.
howMany:An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed. In this case, you should specify at least one new element.
element1, ....,elementNThe element to add to the array. If you don't specify any elements, splice simply removes elements from the array.



Example in HEAD section:

<html>
<head>
<title>Splice Function</title>
<script language="javascript">
arr=new Array("one","two","three","Four");
document.write("<b>My Array before:</b> " + arr);
arr.splice(4,0,"five","six");
document.write("<br><b>my Array after:</b> " + arr);

document.write("<p><b>My Array before:</b> " + arr);
arr.splice(0,2,"1","2");
document.write("<br><b>my Array after:</b> " + arr);
</script>
</head>
</html>


Example in BODY section:

<html>
<head>
<title>Splice Function</title>
</head>
<body>
<script language="javascript">
arr=new Array("one","two","three","Four");
document.write("<b>My Array before:</b> " + arr);
arr.splice(4,0,"five","six");
document.write("<br><b>my Array after:</b> " + arr);

document.write("<p><b>My Array before:</b> " + arr);
arr.splice(0,2,"1","2");
document.write("<br><b>my Array after:</b> " + arr);
</script>
</body>
</html>



OUTPUT:
My Array before: one,two,three,Four
my Array after: one,two,three,Four,five,six

My Array before: one,two,three,Four,five,six
my Array after: 1,2,three,Four,five,six

JavaScript: unshift Function



unshift Function:
Adds one or more elements to the beginning of an array and returns the new length of the array.

Syntax:
arrayname.unshift(element1,element2.........elementn)



Example in HEAD section:

<html>
<head>
<title>unshift Function</title>
<script language="javascript">
var nushifted;
myArray = ["angel", "clown"];
document.writeln("myArray before: " + myArray + "<p>");
unshifted = myArray.unshift("mandarin", "surgeon");
document.writeln("myArray after: " + myArray + "<p>");
</script>
</head>
</html>


Example in BODY section:

<html>
<head>
<title>unshift Function</title>
</head>
<body>
<script language="javascript">
var nushifted;
myArray = ["angel", "clown"];
document.writeln("myArray before: " + myArray + "<p>");
unshifted = myArray.unshift("mandarin", "surgeon");
document.writeln("myArray after: " + myArray + "<p>");
</script>
</body>
</html>




OUTPUT

myArray before: angel,clown

myArray after: angel,clown,mandarin,surgeon

JavaScript: Shift Function



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

Syntax:
arrayname.shift()



Example in HEAD section:

<html>
<head>
<title>Shift Function</title>
<script language="javascript">
myArray = ["angel", "clown", "mandarin", "surgeon"];
document.writeln("myArray before: " + myArray + "<p>");
shifted = myArray.shift();
document.writeln("myArray after: " + myArray + "<p>");
document.writeln("Removed this element: " + shifted);
</script>
</head>
</html>


Example in BODY section:

<html>
<head>
<title>Shift Function</title>
</head>
<body>
<script language="javascript">
myArray = ["angel", "clown", "mandarin", "surgeon"];
document.writeln("myArray before: " + myArray + "<p>");
shifted = myArray.shift();
document.writeln("myArray after: " + myArray + "<p>");
document.writeln("Removed this element: " + shifted);
</script>
</body>
</html>




OUTPUT

myArray before: angel,clown,mandarin,surgeon

myArray after: clown,mandarin,surgeon

Removed this element: angel

JavaScript: Power Function



pow function:
Returns base to the exponent power, that is, baseexponent .
Calculate x raised to y (xy)

Syntax:
pow(x,y)
x is the base number and y is the exponent to which to raise base.

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



Example:

<html>
<head>
<title>Power Function</title>

<script language="javascript">
document.write("calculate 5 <sup> 2 </sup> = " + Math.pow(5,2) + "<br>");
document.write("calcuclate 3 <sup> 5 </sup> = " + Math.pow(3,5) + "<br>");
</script>

</head>
</html>



OUTPUT:

calculate 52 = 25
calcuclate 35 = 243

JavaScript: Min Function



Math.min() Function:
Find the minimum number in the array list.

Syntax:
min(number1,number2,.......numbern)

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



Example

<html>
<head>
<title>MIN Function</title>

<script language="javascript">
document.write("The minimum number is " + Math.min(5,8) + " from(5,8)
");
document.write("The minimum number is " + Math.min(-2,-9) + " from(-2,-9)
");
document.write("The minimum number is " + Math.min(7.25,7.30) + " from(7.25,7.30)");
</script>

</head>
</html>



OUTPUT:

The minimum number is 5 from(5,8)
The minimum number is -9 from(-2,-9)
The minimum number is 7.25 from(7.25,7.30)

Javascript: FLOOR Function



floor function Returns the largest integer less than or equal to a number.

Syntax:
floor(a number)

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


Example in HEAD Section

<html>
<head>
<title>Math.floor function</title>
<script languag="javascript">
document.write("Pass value is -45.65   and return value is = " + Math.floor(45.65) + "<br>");
document.write("Pass value is -45.65   and return value is = " + Math.floor(-45.65));
</script>
</head>
</html>


Example in BODY Section

<html>
<head>
<title>Math.floor function</title>
</head>
<body>
<script languag="javascript">
document.write("Pass value is -45.65   and return value is = " + Math.floor(45.65) + "<br>");
document.write("Pass value is -45.65   and return value is = " + Math.floor(-45.65));
</script>
</body>
</html>




OUTPUT

Pass value is -45.65 and return value is = 45
Pass value is -45.65 and return value is = -46

Javascript: CEIL Function



ceil Function returns the smallest integer greater than or equal to a number.

Syntax:
ceil(a numebr)

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


Example in HEAD Section
<html>
<head>
<title>Math.ceil function</title>
<script language="javascript">
document.write("Pass value is -45.65   and return value is = " + Math.ceil(45.65) + "<br>");
document.write("Pass value is -45.65   and return value is = " + Math.ceil(-45.65));
</script>
</head>
</html>


Example in BODY Section
<html>
<head>
<title>Math.ceil function</title>
</head>
<body>
<script language="javascript">
document.write("Pass value is -45.65   and return value is = " + Math.ceil(45.65) + "<br>");
document.write("Pass value is -45.65   and return value is = " + Math.ceil(-45.65));
</script>
</body>
</html>




OUTPUT

Pass value is -45.65 and return value is = 46
Pass value is -45.65 and return value is = -45
Google