URLSearchParams: values() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
Note: This feature is available inWeb Workers.
Thevalues() method of theURLsearchParamsinterface returns aniterator allowing iterationthrough all values contained in this object. The values are strings.
In this article
Syntax
js
values()Parameters
None.
Return value
Returns aniterator.
Examples
The following example passes a URL search string to theURLSearchParams constructor, then uses the iterator returned byvalues() to print the values to the console.
js
const searchParams = new URLSearchParams("key1=value1&key2=value2");for (const value of searchParams.values()) { console.log(value);}The result is:
value1value2
This example does much the same as above, but first casts the iterator into an array.
js
const searchParams = new URLSearchParams("key1=value1&key2=value2");console.log(Array.from(searchParams.values()));The result is:
['value1', 'value2']
Specifications
| Specification |
|---|
| URL> # dom-urlsearchparams-urlsearchparams> |
Browser compatibility
See also
- The
URLinterface.