web api instance method
URLSearchParams: sort() method
Available in workers
The URLSearchParams.sort() method sorts all key/value
pairs contained in this object in place and returns undefined. Key/value pairs are sorted by the values of the UTF-16 code units 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
sort()
Parameters
None.
Return value
None (undefined).
Examples
// Create a test URLSearchParams object
const 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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.