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