Copyright © tutorialspoint.com

Javascript Array sort() Method

previous next

Advertisements


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.


previous next

Copyright © tutorialspoint.com