URLSearchParams.sort()

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).

Syntax

searchParams.sort();

Return value

Returns undefined.

Example

// 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

Specifications

Specification Status Comment
URL
The definition of 'sort()' in that specification.
Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 61Edge Full support 17Firefox Full support 54IE No support NoOpera Full support 48Safari ? WebView Android Full support 61Chrome Android Full support 61Edge Mobile Full support 17Firefox Android Full support 54Opera Android Full support 48Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Contributors to this page: sideshowbarker, fscholz, jpmedley, ziyunfei
Last updated by: sideshowbarker,