Sorts an Array.
Syntaxsort( sortFunction )
The sorted array.
ExamplesThe following example shows how to use the sort method.
var a = new Array(4, 11, 2, 10, 3, 1);
var b = a.sort();
document.write(b);
document.write("<br/>");
b = a.sort(CompareForSort);
document.write(b);
document.write("<br/>");
function CompareForSort(first, second)
{
if (first == second)
return 0;
if (first < second)
return -1;
else
return 1;
}
Remarks
The sort method sorts the Array object in place; no new Array object is created during execution.
If you supply a function in the sortFunction argument, it must return one of the following values:
15.4.4.11 Array.prototype.sort (comparefn) ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011
AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4