Standard built-ins
Array.prototype.sort()
Reorders the receiver and returns it. Default order compares defined values as strings. A consistent comparator returns negative, zero or positive; ties are stable. Ordinary holes sort after undefined. No comparator call count is guaranteed.
Formal Syntax & Structure
javascript syntaxjavascript
array.sort(compareFn?)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| compareFn | function | Optional ordering comparator; defaults to string ordering. |
Return Value
Array
The same sorted receiver.
Working Example
Example Snippetjavascript
const a=[8,10,2]; const b=a.sort((x,y)=>x-y); console.log(b.join(","),a===b);