JavaScript Basics
JavaScript Objects
JavaScript Advanced
JS Useful References
JS Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Javascript Array sort() Method
Description:
Javascript array sort() method sorts the elements of an array.
Syntax:
array.sort( compareFunction );
|
Here is the detail of parameters:
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
|
To understand it in better way you can Try it yourself.
|
|
|