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

JavaScript: Join Function



join Function:
Joins all elements of an array into a string.

Syntax:
join(separator);



Example in HEAD section:

<html>
<head>
<script language="javacsript">
num=new Array("One""two","Three","our");
var str;
str=num.join();
document.write(str + "<br>");
str=num.join(" , ");
document.write(str + "<br>");
str=num.join(" + ");
document.write(str + "<br>");
</script>
</head>
</html>


Example in BODY section:

<html>
<head>
<script language="javacsript">
</head>
<body>
num=new Array("One""two","Three","our");
var str;
str=num.join();
document.write(str + "<br>");
str=num.join(" , ");
document.write(str + "<br>");
str=num.join(" + ");
document.write(str + "<br>");
</script>
</body>
</html>




OUTPUT

One,two,Three,Four
One , two , Three , Four
One + two + Three + Four

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: CharAt Function



charAt Function:
Using the charAt method you can find out the element in a string.

Syntax:
variablename.charAt(indexnumber);



Example in HEAD section:

<html>
<head>
<title>charAt Function</title>
<script language="javascript">
var anystring="Hello World";
document.write("The character at index 0 is " +anystring.charAt(0)+"<br>");
document.write("The character at index 1 is " +anystring.charAt(1)+"<br>");
document.write("The character at index 2 is " +anystring.charAt(2)+"<br>");
document.write("The character at index 3 is " +anystring.charAt(3)+"<br>");
document.write("The character at index 4 is " +anystring.charAt(4)+"<br>");
document.write("The character at index 5 is " +anystring.charAt(5)+"<br>");
document.write("The character at index 6 is " +anystring.charAt(6)+"<br>");
document.write("The character at index 7 is " +anystring.charAt(7)+"<br>");
document.write("The character at index 8 is " +anystring.charAt(8)+"<br>");
document.write("The character at index 9 is " +anystring.charAt(9)+"<br>");
document.write("The character at index 10 is " +anystring.charAt(10));
</script>
</head>
</html>


Example in BODY Section:

<html>
<head>
<title>charAt Function</title>
</head>
<body>
<script language="javascript">
var anystring="Hello World";
document.write("The character at index 0 is " +anystring.charAt(0)+"<br>");
document.write("The character at index 1 is " +anystring.charAt(1)+"<br>");
document.write("The character at index 2 is " +anystring.charAt(2)+"<br>");
document.write("The character at index 3 is " +anystring.charAt(3)+"<br>");
document.write("The character at index 4 is " +anystring.charAt(4)+"<br>");
document.write("The character at index 5 is " +anystring.charAt(5)+"<br>");
document.write("The character at index 6 is " +anystring.charAt(6)+"<br>");
document.write("The character at index 7 is " +anystring.charAt(7)+"<br>");
document.write("The character at index 8 is " +anystring.charAt(8)+"<br>");
document.write("The character at index 9 is " +anystring.charAt(9)+"<br>");
document.write("The character at index 10 is " +anystring.charAt(10));
</script>
</body>
</html>



OUTPUT

These lines display the following:

The character at index 0 is H
The character at index 1 is e
The character at index 2 is l
The character at index 3 is l
The character at index 4 is o
The character at index 5 is
The character at index 6 is W
The character at index 7 is o
The character at index 8 is r
The character at index 9 is l
The character at index 10 is d

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

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: isNaN Function



isNaN Function :-
Evaluates an argument to determine if it is not a number.

Syntax :-
isNaN(value)
value = The value you want to evaluate.

Description :-
isNaN is a top-level function and is not associated with any object.

On platforms that support NaN, the parseFloat and parseInt functions return NaN when they evaluate a value that is not a number. isNaN returns true if passed NaN, and false otherwise.



Example:

<html>
<head>
<title>isNaN Fnction</title>

<script language="javascript">
function check()
{
var phone=f1.phone.value;
if(isNaN(phone))
alert("Characters are not allowed in the Phone Number");
else
alert("Your Phone Number is Accepted");
}
</script>

</head>
<body>

<form name="f1">
Phone: <input type="text" name="phone" size="20">
<input type="button" value="check" onclick="check()">
</form>

</body>
</html>

JavaScript: Squareroot Function



sqrt Function :-
Returns the square root of a number.

Suntax :-
sqrt(number)

Description :-
If the value of number is negative,sqrt returns NaN. Because sqrt is a static method of Math,you always use it as Math.sqrt(), rather than as a method of a Math object you created.



Example:

<html>
<head>
<title>Calculate Squareroot</title>

<script language="javascript">
function calcsqrt()
{
var value=f1.sqrt.value;
alert("The Squareroot of " + value + " is " + Math.sqrt(value));
}
</script>

</head>
<body>

<form name="f1">
<input type="text" name="sqrt" value="Enter Number" size="20">
<input type="button" value="Calculate" onclick="calcsqrt()">
</form>

</body>
</html>

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

Javascript: BIG Function



big Funtion
                 
Causes a string to be displayed in a big font as if it were in a BIG tag.

Syntax:
big()

Description:
                   
Use the big method with the write or write methods to format and display a string in a document. In server-side JavaScript, use the write function to display the string.



Example:

<html>
<head>
<title>Big function</title>

<script languge="javscript">
function makebig()
{
var name=f1.t1.value.big();
document.write(name);
}
</script>

</head>
<body>

<form name="f1">
<input type="text" name="t1" value="click" size="20">
<input type="button" onclick="makebig()" value="click">
</form>

</body>
</html>
Google