This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The URLSearchParams.sort() method sort all key/value pairs contained in this object in place and return 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).
searchParams.sort();
Returns undefined.
// Create a test URLSearchParams object
var 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
| Specification | Status | Comment |
|---|---|---|
| URL The definition of 'sort()' in that specification. | Living Standard | Initial definition |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | 61 | 17 | 54 | No | 48 | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | 61 | 61 | 17 | 54 | 48 | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/sort