JavaScript Array sort() methodThe JavaScript array sort() method is used to arrange the array elements in some order. By default, sort() method follows the ascending order. SyntaxThe sort() method is represented by the following syntax: ParametercompareFunction - It is optional. It represents a function that provides an alternative sort order. ReturnAn array of sorted elements JavaScript Array sort() method exampleHere, we will understand sort() method through various examples. Example 1Let's see a simple example to sort the array of string elements. Test it NowOutput: AngularJS,Bootstrap,JQuery,Node.js Example 2Let's see a simple example to sort the array of integer elements. Test it NowOutput: 1,2,4,5,8 Example 3Let's see an example to arrange the elements in ascending order using function. Test it NowOutput: 1,2,4,5,8 Example 4Let's see an example to arrange the elements in descending order using function. Test it NowOutput: 8,5,4,2,1 Example 5Let's see an example to extract minimum value from an array. Test it NowOutput: 1 Example 6Let's see an example to extract maximum value from an array. Test it NowOutput: 8 Next TopicJavaScript Array |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India