---
title: "getQueryParam"
description: "Read a single query parameter value from a URL by key, returning the first match or null when the parameter is not present."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/get-query-param"
---
# getQueryParam

> Read a single query parameter value from a URL by key, returning the first match or null when the parameter is not present.

## Usage

`getQueryParam` retrieves the value of a specific query parameter from a URL.

```ts
import { getQueryParam } from '@movk/core'

getQueryParam('https://example.com?name=John&age=30', 'name')
// 'John'

getQueryParam('https://example.com?tags=a&tags=b', 'tags')
// 'a' (returns the first value)

getQueryParam('https://example.com', 'name')
// null
```

## API

### `getQueryParam(url, key)`

Get the value of a specific query parameter from a URL.

### Parameters

**url** (`string`) *required*: The URL string.

**key** (`string`) *required*: The parameter key.

### Returns

**returns** (`string | null`): The parameter value, or null if not present.

## Note

- If the parameter has multiple values, only the first is returned.
- Use [`getQueryParams`](https://core.mhaibaraai.cn/docs/utilities/url/get-query-params) to retrieve all values.

## Changelog

See commit history for [src/utilities/url/query.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/query.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/query.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
