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
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week