Headers.prototype.entries
Returns an iterator allowing to go through all key/value pairs contained in the Headers object
Syntax
headers.entries()Return Value
An iterator of [name, value] pairs
Examples
const res = await fetch('/api/data')
for (const [name, value] of res.headers.entries()) {
console.log(`${name}: ${value}`)
}function headersToObject(headers: Headers): Record<string, string> {
const obj: Record<string, string> = {}
for (const [key, val] of headers.entries()) {
obj[key] = val
}
return obj
}const headers = new Headers({ 'A': '1', 'B': '2' })
const pairs = [...headers.entries()]
console.log(pairs) // [['a','1'], ['b','2']]Understanding Headers.prototype.entries
The Headers.prototype.entries method in JavaScript returns an iterator allowing to go through all key/value pairs contained in the Headers object. 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.entries(). When called, it returns an iterator of [name, value] pairs. Understanding when and how to use entries() helps you write more expressive, readable code.
Common use cases for Headers.prototype.entries include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like fetch-headers-keys, fetch-headers-values, fetch-headers-get, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Headers.prototype.entries 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
Headers.prototype.keysReturns an iterator allowing you to go through all keys of the key/value pairs contained in the Headers object
Headers.prototype.valuesReturns an iterator allowing you to go through all values of the key/value pairs contained in the Headers object
Headers.prototype.getReturns the value of the specified header from a Headers object, or null if it does not exist
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.