Since September 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Note: This feature is available in Web Workers.
The size read-only property of the URLSearchParams interface indicates the total number of search parameter entries.
A number indicating the total number of search parameter entries in the URLSearchParams object.
You can get the total number of search parameter entries like so:
const searchParams = new URLSearchParams("c=4&a=2&b=3&a=1");
searchParams.size; // 4
Note how the a parameter is given twice, but size returns the number of all given entries (4) and not 3. To get the amount of unique keys, you can use a Set, for example:
[...new Set(searchParams.keys())].length; // 3
The size property is useful for checking whether there are any search parameters at all:
const url = new URL("https://example.com?foo=1&bar=2");
if (url.searchParams.size) {
console.log("URL has search parameters!");
}
| Specification |
|---|
| URL> # dom-urlsearchparams-size> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
size |
113 | 113 | 112 | 99 | 17 | 113 | 112 | 76 | 17 | 23.0 | 113 | 17 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/size