URLSearchParams: size property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2023.

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.

Value

A number indicating the total number of search parameter entries in the URLSearchParams object.

Examples

Getting the amount of search parameter entries

You can get the total number of search parameter entries like so:

js
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:

js
[...new Set(searchParams.keys())].length; // 3

Checking if search parameters exist

The size property is useful for checking whether there are any search parameters at all:

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

if (url.searchParams.size) {
  console.log("URL has search parameters!");
}

Specifications

Specification
URL
# dom-urlsearchparams-size

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
size
Chrome – Full support
Chrome 113 (Release date: 2023-05-02)
footnote Full support
Edge – Full support
Edge 113 (Release date: 2023-05-05)
footnote Full support
Firefox – Full support
Firefox 112 (Release date: 2023-04-11)
footnote Full support
Opera – Full support
Opera 99 (Release date: 2023-05-16)
footnote Full support
Safari – Full support
Safari 17 (Release date: 2023-09-18)
footnote Full support
Chrome Android – Full support
Chrome Android 113 (Release date: 2023-05-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 112 (Release date: 2023-04-11)
footnote Full support
Opera Android – Full support
Opera Android 76 (Release date: 2023-06-26)
footnote Full support
Safari on iOS – Full support
Safari on iOS 17 (Release date: 2023-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 23 (Release date: 2023-10-18)
footnote Full support
WebView Android – Full support
WebView Android 113 (Release date: 2023-05-02)
footnote Full support
WebView on iOS – Full support
WebView on iOS 17 (Release date: 2023-09-18)
footnote Full support
Bun – Full support
Bun 1.0.2 (Release date: 2023-09-15)
footnote Full support
Deno – Full support
Deno 1.32 (Release date: 2023-03-23)
footnote Full support
Node.js – No support
Node.js 18.16 – 18.20 (Release date: 2023-04-13)
footnote Removed in 19 and later
Node.js – Full support
Node.js 19.8 (Release date: 2023-03-14)
footnote Full support

Legend

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

Full support
Full support
Has more compatibility info.

See also