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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
get |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.