URLSearchParams: sort() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available in Web Workers.
The URLSearchParams.sort()
method sorts all key/value
pairs contained in this object in place and returns undefined
. The sort
order is according to unicode code points of the keys. This method uses a stable sorting
algorithm (i.e. the relative order between key/value pairs with equal keys will be
preserved).
Syntax
js
sort()
Parameters
None.
Return value
None (undefined
).
Examples
js
// Create a test URLSearchParams object
const searchParams = new URLSearchParams("c=4&a=2&b=3&a=1");
// Sort the key/value pairs
searchParams.sort();
// Display the sorted query string
console.log(searchParams.toString());
The result is:
a=2&a=1&b=3&c=4
Specifications
Specification |
---|
URL # dom-urlsearchparams-sort |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sort |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.