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



Return value

Returns undefined.


// Create a test URLSearchParams object 
var searchParams = new URLSearchParams("c=4&a=2&b=3&a=1"); 

// Sort the key/value pairs

// Display the sorted query string

The result is:



Specification Status Comment
The definition of 'sort() (as iterator<>)' in that specification.
Living Standard Initial definition

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 61 No support No support 48 No support
Feature Android Webview Chrome for Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 61 61 No support No support No support 48 No support

Document Tags and Contributors

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