---
title: "getQueryParams"
description: "从 URL 中获取所有同名查询参数的值数组，适用于处理多值参数（如复选框筛选）。"
seo_title: "getQueryParams"
seo_description: "Read every value of a repeated query parameter from a URL by key, returning an array so multi-value filters and tags are easy to handle."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/get-query-params"
---
# getQueryParams

> 从 URL 中获取所有同名查询参数的值数组，适用于处理多值参数（如复选框筛选）。

## 用法

`getQueryParams` 函数用于从 URL 获取所有指定查询参数的值(用于多值参数)。

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

getQueryParams('https://example.com?tags=a&tags=b&tags=c', 'tags')
// ['a', 'b', 'c']

getQueryParams('https://example.com?name=John', 'name')
// ['John']

getQueryParams('https://example.com', 'name')
// []
```

## API

### `getQueryParams(url, key)`

从 URL 获取所有指定查询参数的值。

### 参数

**url** (`string`) *required*: URL 字符串。

**key** (`string`) *required*: 参数名。

### 返回值

**返回值** (`string[]`): 参数值数组。

## Changelog

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


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
