URLSearchParams: toString() メソッド

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.

toString()URLSearchParams インターフェイスのメソッドで、URL での使用に適したクエリー文字列を返します。

メモ: このメソッドは、疑問符のないクエリー文字列を返します。これは、それを含む window.location.search とは異なります。

メモ: この機能はウェブワーカー内で利用可能です。

構文

js
toString()

引数

なし。

返値

疑問符を除いた文字列です。(検索パラメーターが設定されていない場合は空文字列を返します。)

js
const url = new URL("https://example.com?foo=1&bar=2");
const params = new URLSearchParams(url.search);

// 2番目の foo パラメーターの追加
params.append("foo", 4);
console.log(params.toString()); // 'foo=1&bar=2&foo=4' と表示

仕様書

Specification
URL
# urlsearchparams-stringification-behavior

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
toString

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連項目