# Get the value of a param from a URL

Parse an absolute URL and read one query parameter.

Canonical: https://1loc.dev/misc/get-the-value-of-a-param-from-a-url/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function getParam({ url, param }) { return new URL(url).searchParams.get(param); }
```

## Input

```json
{
  "url": "https://example.com/unsubscribe?token=abc123&list=news",
  "param": "token"
}
```

## Expected output

```json
"abc123"
```

## Edge case

Input:
```json
{
  "url": "https://example.com/",
  "param": "token"
}
```
Output:
```json
null
```

## Limits

- A missing parameter returns null. Repeated parameters return the first value; use getAll for every value.
- Treat tokens from links as credentials: never log them.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/get-the-value-of-a-param-from-a-url.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Uses URL.searchParams directly; validates an absolute URL. Original MDX retained as inert source evidence.
