Description:
Javascript array sort() method sorts the elements of an array.
Syntax:
array.sort( compareFunction ); |
Here is the detail of parameters:
- compareFunction : Specifies a function that defines the sort order. If omitted, the array is sorted lexicographically.
Return Value:
Returns a sorted array.
Example:
<html> <head> <title>JavaScript Array sort Method</title> </head> <body> <script type="text/javascript"> var arr = new Array("orange", "mango", "banana", "sugar"); var sorted = arr.sort(); document.write("Returned string is : " + sorted ); </script> </body> </html> |
This will produce following result:
Returned array is : banana,mango,orange,sugar |
No comments:
Post a Comment