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.

JavaScript: Sort Function



sort Function:
Sorts the elements of an array.

Syntax:
sort()

Example in HEAD section:

<html>
<head>
<title>Sort Function</title>
<script language="javascript">
names=new Array("Mango","Apple","Orange","Water Melon","Bannana","Strawberry");
document.write("Array is <br>" + names + "<p>");
var str1=names.sort();
document.write("After Sorting this array is<br>" +str1);
<script>
</head>
</html>


Example in BODY section:

<html>
<head>
<title>Sort Function</title>
</head>
<body>
<script language="javascript">
names=new Array("Mango","Apple","Orange","Water Melon","Bannana","Strawberry");
document.write("Array is <br>" + names + "<p>");
var str1=names.sort();
document.write("After Sorting this array is<br>" +str1);
<script>
</body>
</html>



OUTPUT:

Array is
Mango,Apple,Orange,Water Melon,Bannana,Strawberry

After Sorting this array is
Apple,Bannana,Mango,Orange,Strawberry,Water Melon

No comments:

Post a Comment

Google