URLSearchParams.sort()

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

Note: This feature is available in Web Workers.

Syntax

searchParams.sort();

Parameters

None.

Return value

undefined.

Examples

// 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 AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 61Edge Full support 17Firefox Full support 54IE No support NoOpera Full support 48Safari Full support YesWebView Android Full support 61Chrome Android Full support 61Edge Mobile No support NoFirefox Android Full support 54Opera Android Full support 48Safari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support

Document Tags and Contributors

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