createSearchParams
On this page

createSearchParams

Summary

Reference Documentation ↗

Creates a URLSearchParams object using the given initializer.

This is identical to new URLSearchParams(init) except it also supports arrays as values in the object form of the initializer instead of just strings. This is convenient when you need multiple values for a given key, but don't want to use an array initializer.

// Instead of:
let searchParams = new URLSearchParams([
  ["sort", "name"],
  ["sort", "price"],
]);

// You can do:
let searchParams = createSearchParams({
  sort: ["name", "price"],
});

Signature

function createSearchParams(init: URLSearchParamsInit = ""): URLSearchParams

Params

init

The value used to initialize the URL search parameters.

Returns

A URLSearchParams object containing the initialized search parameters.

Docs and examples CC 4.0
Edit