What is array sort in JavaScript

In this article I am going to explain array sort method of JavaScript.
  • 1823

Array sort method in JavaScript

It sorts the elements of an array.

Syntax of array sort method

array.sort(function);


Parameters in some  method:

  • function

    It is optional,the function define the sort order.

Return value of sort method

It returns a sorted array.
 

Example of sort function
 

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Array Sort Method</title>
</head>
<body>
<script type="text/javascript">
var a = ['c','d','a','k'];
a.sort();
alert(a);
</script>
</body>
</html>


Output:


zzzzsort.jpg


Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.