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 add. Show all posts
Showing posts with label add. 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: Concat Function



concat Function:
Joins two arrays and returns a new array.

Syntax:
concat(arrayName2,arrayName3, ...,arrayNameN);



Example in HEAD section:

<html>
<head>
<title>Concat Function</title>
<script language="javascript">
var s1="Oh "
var s2="what a beautiful "
var s3="morning"
var s4=s1.concat(s2,s3)
document.write(s4);
</script>
</head>
</html>


Example in BODY section:

<html>
<head>
<title>Concat Function</title>
</head>
<body>
<script language="javascript">
var s1="Oh "
var s2="what a beautiful "
var s3="morning"
var s4=s1.concat(s2,s3)
document.write(s4);
</script>
</body>
</html>




OUTPUT

Oh what a beautiful morning

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
Google