Home

URLSearchParams

URLSearchParams is a Web API interface that provides convenient access to the query component of a URL. It represents the query string as an ordered list of key-value pairs and supports reading, adding, removing, and updating parameters without manual string manipulation. It is part of the WHATWG URL API and is implemented in all major browsers and in Node.js.

Construction and mutability: URLSearchParams can be created from a query string, from an existing URLSearchParams, or

Core methods and properties: The interface includes append(name, value) to add a parameter, delete(name) to remove

Iteration and serialization: toString() returns a percent-encoded query string representing the current parameters, using UTF-8 encoding

Compatibility and usage: URLSearchParams is widely supported in modern browsers and available in Node.js. It is

from
an
iterable
of
[name,
value]
pairs.
If
the
input
begins
with
a
question
mark,
the
mark
is
ignored.
The
instance
is
mutable,
so
changes
affect
the
serialized
form
returned
by
toString()
and
can
be
reflected
in
the
URL.
all
values
for
a
name,
get(name)
to
retrieve
the
first
value,
getAll(name)
to
retrieve
all
values,
has(name)
to
check
for
presence,
set(name,
value)
to
replace
values,
and
sort()
to
order
parameters
by
name.
It
also
exposes
length
and
provides
iterators
keys(),
values(),
and
entries();
the
object
is
iterable
via
for...of.
(spaces
become
%20).
The
object
can
be
used
to
build
URLs
or
fetch
requests
by
appending
the
serialized
string
to
a
base
URL
or
by
syncing
with
url.searchParams.
commonly
used
to
read
location.search,
modify
query
parameters,
and
construct
new
request
URLs
in
web
applications.