URLSearchParams: sort() method
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
Parameters
Return value
Examples
const searchParams = new URLSearchParams("c=4&a=2&b=3&a=1");
searchParams.sort();
console.log(searchParams.toString());
The result is:
a=2&a=1&b=3&c=4
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
sort |
61 |
17 |
54 |
No |
48 |
11 |
61 |
61 |
54 |
45 |
11 |
8.0 |