URLSearchParams: get() メソッド

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.

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

get()URLSearchParams インターフェイスのメソッドで、指定された検索パラメーターに関連付けられた最初の値を返します。

構文

js
get(name)

引数

name

返すパラメーターの名前。

返値

指定された検索パラメーターが見つかった場合は文字列です。それ以外の場合は null です。

ページの URL が https://example.com/?name=Jonathan&age=18 の場合、次のように 'name' および 'age' のパラメーターを解釈できます。

js
let params = new URLSearchParams(document.location.search);
let name = params.get("name"); // 文字列 "Jonathan" です
let age = parseInt(params.get("age"), 10); // 数値 18 です

クエリー文字列に存在しないパラメーターを要求すると、null が返されます。

js
let address = params.get("address"); // null

仕様書

Specification
URL
# dom-urlsearchparams-get

ブラウザーの互換性

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
get

Legend

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

Full support
Full support