How to use sorted functions in javascript
This article introduces the knowledge of "how to use the sorted functions in javascript". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The function of sorting in javascript is "sort ()", and the sort () function is used to sort the elements of the array, which can be alphabetical or numeric, and can be sorted in ascending or descending order. The default sorting order is ascending alphabetical order, and the syntax is "array.sort (sortfunction)".
The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.
What is the function to sort in javascript
The sort () method is used to sort the elements of the array.
The sort order can be alphabetic or numeric, in ascending or descending order.
The default sort order is ascending alphabetically.
Note: "40" will precede "5" when the numbers are in alphabetical order.
Using numeric sorting, you must call it through a function as an argument.
Function specifies whether the numbers are sorted in ascending or descending order.
This may be hard to understand, and you can learn more about it through an example at the bottom of this page.
Note: this method will change the original array.
The syntax is as follows:
Array.sort (sortfunction)
Sortfunction is an optional parameter. Used to specify the sort order. Must be a function.
Examples are as follows:
The rookie tutorial (runoob.com) clicks the button to sort the array in ascending order.