URLSearchParams: sort() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
URLSearchParams.sort()
メソッドは、このオブジェクトに含まれるすべてのキー/値のペアをその場でソートし、undefined
を返します。 ソート順は、キーの Unicode コードポイントに従います。 このメソッドは、安定したソートアルゴリズムを使用します(つまり、等しいキーを持つキー/値のペア間の相対的な順序が保持されます)。
メモ: この機能はウェブワーカー内で利用可能です。
構文
js
sort()
引数
なし。
返値
なし (undefined
)。
例
js
// テスト用の URLSearchParams オブジェクトの作成
const searchParams = new URLSearchParams("c=4&a=2&b=3&a=1");
// キー/値のペアのソート
searchParams.sort();
// ソートされたクエリー文字列の表示
console.log(searchParams.toString());
結果は次のとおりです。
a=2&a=1&b=3&c=4
仕様書
Specification |
---|
URL # dom-urlsearchparams-sort |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sort |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.