Array.sort()

JavaScript 1.1+, ECMAScript 1.0+, JScript 3.0+ Nav3+, NES3+, IE 4+ Syntax

							array.sort()
array.sort(function)

Description

The sort() method rearranges the elements of the array based on a sorting order. Table 6.15 lists the argument associated with this method. If the method has no parameters, JavaScript attempts to convert all the elements of the array to strings and then sort them alphabetically. If the array should be sorted some other way, a function must be provided to handle the new sorting algorithm.

Table 6.15. Argument Associated with sort()
Type Item Description
Argument function A function designated to handle the sorting of the array.

As mentioned before, if the array should be sorted some other way than alphabetically, ...

Get Pure JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.