Headers: get() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

Note: This feature is available in Web Workers.

The get() method of the Headers interface returns a byte string of all the values of a header within a Headers object with a given name. If the requested header doesn't exist in the Headers object, it returns null.

For security reasons, some headers can only be controlled by the user agent. These headers include the forbidden request headers and forbidden response header names.

Syntax

js
get(name)

Parameters

name

The name of the HTTP header whose values you want to retrieve from the Headers object. If the given name doesn't match the field-name production in the HTTP specification, this method throws a TypeError. The name is case-insensitive.

Return value

A String sequence representing the values of the retrieved header or null if this header is not set.

Examples

Creating an empty Headers object is simple:

js
const myHeaders = new Headers(); // Currently empty
myHeaders.get("Not-Set"); // Returns null

You could add a header to this using Headers.append, then retrieve it using get():

js
myHeaders.append("Content-Type", "image/jpeg");
myHeaders.get("Content-Type"); // Returns "image/jpeg"

If the header has multiple values associated with it, the byte string will contain all the values, in the order they were added to the Headers object:

js
myHeaders.append("Accept-Encoding", "deflate");
myHeaders.append("Accept-Encoding", "gzip");
myHeaders.get("Accept-Encoding"); // Returns "deflate, gzip"
myHeaders
  .get("Accept-Encoding")
  .split(",")
  .map((v) => v.trimStart()); // Returns [ "deflate", "gzip" ]

Specifications

Specification
Fetch
# ref-for-dom-headers-get①

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
get
Chrome – Full support
Chrome 42 (Release date: 2015-04-14)
footnote
footnote Before version 57, get() returns only the first value for the specified header.
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 39 (Release date: 2015-07-02)
footnote
footnote Before version 52, get() returns only the first value for the specified header.
Opera – Full support
Opera 29 (Release date: 2015-04-28)
footnote
footnote Before version 44, get() returns only the first value for the specified header.
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 42 (Release date: 2015-04-15)
footnote
footnote Before version 57, get() returns only the first value for the specified header.
Firefox for Android – Full support
Firefox for Android 39 (Release date: 2015-07-02)
footnote
footnote Before version 52, get() returns only the first value for the specified header.
Opera Android – Full support
Opera Android 29 (Release date: 2015-04-28)
footnote
footnote Before version 43, get() returns only the first value for the specified header.
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote
footnote Before version 7.0, get() returns only the first value for the specified header.
WebView Android – Full support
WebView Android 42 (Release date: 2015-04-15)
footnote
footnote Before version 57, get() returns only the first value for the specified header.
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 18 (Release date: 2022-04-19)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

See also