Headers

Headers.prototype.entries

Returns an iterator allowing to go through all key/value pairs contained in the Headers object

Syntax

JavaScript
headers.entries()

Return Value

An iterator of [name, value] pairs

Examples

Basic Usage
const res = await fetch('/api/data')
for (const [name, value] of res.headers.entries()) {
  console.log(`${name}: ${value}`)
}
Practical Example
function headersToObject(headers: Headers): Record<string, string> {
  const obj: Record<string, string> = {}
  for (const [key, val] of headers.entries()) {
    obj[key] = val
  }
  return obj
}
Advanced Usage
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

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.