Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

URLSearchParams.forEach — traversing query parameters

URLSearchParams.forEach calls a function for each parameter pair, preserving order and repeated names. The callback arguments are the value, key, and parameter object.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

params.forEach(callbackFn[, thisArg])
callbackFn(value, key, params)

URLSearchParams.forEach visits each pair in list order, including repeated keys. The callback receives (value, key, params), not an index. Keys and values are strings.

Optional thisArg supplies this for an ordinary function; it does not change an arrow function's this. The method returns undefined; callback results do not stop iteration.

Iteration is synchronous and does not await promises. Mutating the list during traversal can change which entries are visited; avoid modifying it inside the callback.

The example preserves both tag entries; parsing converts + to a space. This is a URL-standard Web API, not an ECMAScript-edition feature. Check availability in your target environment.

Examples

const params = new URLSearchParams('tag=js&tag=web&q=hello+world');
const lines = [];
params.forEach((value, key) => {
  lines.push(`${key}: ${value}`);
});
console.log(lines.join('\n'));

Result

tag: js
tag: web
q: hello world

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources