Skip to content

Function: getQueryParam()

ts
function getQueryParam(url, key): string | null;

Reads a query parameter from a URL string.

Parameters

ParameterTypeDescription
urlstringThe source URL.
keystringThe query parameter name.

Returns

string | null

The parameter value, or null if missing.

Example

ts
getQueryParam('https://example.com?id=5', 'id')
// => '5'

Since

1.0.0

Released under the MIT License.