Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

URLSearchParams.sort(): sorting parameters by name

URLSearchParams.sort() orders parameters by name, mutating the object. Entries with identical names retain their original order.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

params.sort()

params.sort() sorts ascending by the UTF-16 code units of names, not values. It is case-sensitive, not locale-aware or numeric. Sorting is stable: entries with identical names retain their order. The method takes no arguments, mutates the object, and returns undefined.

Calling it on url.searchParams updates the URL; reserialization can change encoding, such as %20 to +. To preserve the original, copy it with new URLSearchParams(params). This is a Web API defined by the URL Standard, not an ECMAScript method.

Examples

const params = new URLSearchParams('b=2&a=z&a=1&A=0');
const result = params.sort();
console.log(params.toString());
console.log(result);

Result

A=0&a=z&a=1&b=2
undefined

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources