URLSearchParams: getAll() メソッド

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.

We'd love to hear more about your role and the company you work for
Please help us by answering a few questions.

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

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

構文

js
getAll(name)

引数

name

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

返値

文字列の配列です。

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

// 2 つ目の foo パラメーターを追加します。
params.append("foo", 4);

console.log(params.getAll("foo")); // ["1","4"] を表示します。

仕様書

Specification
URL
# dom-urlsearchparams-getall

ブラウザーの互換性