Dev Helpers

Node.js / Query parameters

Count parameter entries

Dev Helpers · January 2, 2026

The size of URLSearchParams counts entries, including repeated keys. It can differ from the number of distinct parameter names.

Worked example

import { URLSearchParams } from "node:url";
console.log(new URLSearchParams("a=1&a=2").size);

Result

2

Implementation notes

Replacing a key can collapse existing repeated values. Use append when a second occurrence is meant to remain part of the request.

Try it yourself

Add the same filter twice and compare both counts.

Open the Node.js example →

Editorial date January 2, 2026 · Published December 6, 2026

Related articles

Safely parse malformed input

Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.

Checksum bytes with CRC32

CRC32 is useful for detecting accidental changes to a byte sequence. Record the input encoding so different producers compute the same checksum.

Attach details to a mark

Performance marks can carry details about the operation they describe. Small stable identifiers are easier to aggregate than large payloads.