URLSearchParams

URLSearchParams.prototype.get

Returns the first value associated to the given search parameter

Syntax

JavaScript
params.get(name)

Parameters

ParameterTypeDescription
namestringThe name of the parameter to get

Return Value

The value string, or null if not found

Examples

Basic Usage
const params = new URLSearchParams('q=hello&page=1')
console.log(params.get('q')) // 'hello'
console.log(params.get('missing')) // null
Practical Example
const params = new URLSearchParams(window.location.search)
const token = params.get('token')
if (token) console.log('Token:', token)
Advanced Usage
function getQueryParam(name: string): string | null {
  const params = new URLSearchParams(window.location.search)
  return params.get(name)
}

Understanding URLSearchParams.prototype.get

The URLSearchParams.prototype.get method in JavaScript returns the first value associated to the given search parameter. It belongs to the URLSearchParams object and is one of the most widely used methods for working with urlsearchparams values in modern JavaScript and TypeScript applications.

The method signature is params.get(name). It accepts 1 parameter: name. When called, it returns the value string, or null if not found. Understanding when and how to use get() helps you write more expressive, readable code.

Common use cases for URLSearchParams.prototype.get include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like urlsearchparams-getall, urlsearchparams-set, urlsearchparams-has, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for URLSearchParams.prototype.get is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More URLSearchParams Methods

Other methods in the URLSearchParams object

Related Tools

More URLSearchParams Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.