This Fetch API interface allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing. A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs. You can add to this using methods like append() (see Examples.) In all methods of this interface, header names are matched by case-insensitive byte sequence.
Symbol
Headers
class Headers
Returns an iterator allowing to go through all key/value pairs contained in this object.
Get all headers matching the name
Only supports
"Set-Cookie"
. All other headers are empty arrays.@param nameThe header name to get
@returnsAn array of header values
const headers = new Headers(); headers.append("Set-Cookie", "foo=bar"); headers.append("Set-Cookie", "baz=qux"); headers.getAll("Set-Cookie"); // ["foo=bar", "baz=qux"]
Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.
Convert Headers to a plain JavaScript object.
About 10x faster than
Object.fromEntries(headers.entries())
Called when you run
JSON.stringify(headers)
Does not preserve insertion order. Well-known header names are lowercased. Other header names are left as-is.
Returns an iterator allowing to go through all values of the key/value pairs contained in this object.