MDN wants to talk to developers like you: https://qsurvey.mozilla.com/s3/8d22564490d8

URLSearchParams.sort()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

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() (as iterator<>)' in that specification.
Living Standard Initial definition

Browser compatibility

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

Document Tags and Contributors

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