Headers

Headers.prototype.get

Returns the value of the specified header from a Headers object, or null if it does not exist

Syntax

JavaScript
headers.get(name)

Parameters

ParameterTypeDescription
namestringThe name of the HTTP header

Return Value

A string containing the header value, or null

Examples

Basic Usage
const res = await fetch('/api/data')
const contentType = res.headers.get('content-type')
console.log(contentType)
Practical Example
const res = await fetch('/api/paginated')
const total = res.headers.get('X-Total-Count')
console.log('Total items:', total)
Advanced Usage
async function getEtag(url: string) {
  const res = await fetch(url, { method: 'HEAD' })
  return res.headers.get('ETag')
}

Understanding Headers.prototype.get

The Headers.prototype.get method in JavaScript returns the value of the specified header from a Headers object, or null if it does not exist. It belongs to the Headers object and is one of the most widely used methods for working with headers values in modern JavaScript and TypeScript applications.

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

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

Browser support for Headers.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 Headers Methods

Other methods in the Headers object

Related Tools

More Headers Methods

Explore JavaScript Methods

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