Headers

Headers.prototype.append

Appends a new value onto an existing header inside a Headers object, or adds the header if it does not already exist

Syntax

JavaScript
headers.append(name, value)

Parameters

ParameterTypeDescription
namestringThe name of the HTTP header
valuestringThe value to append

Return Value

undefined

Examples

Basic Usage
const headers = new Headers()
headers.append('Accept', 'text/html')
headers.append('Accept', 'application/json')
console.log(headers.get('Accept'))
// 'text/html, application/json'
Practical Example
function addCookies(headers: Headers, cookies: string[]) {
  cookies.forEach(c => headers.append('Set-Cookie', c))
}
Advanced Usage
const headers = new Headers()
headers.append('X-Tags', 'a')
headers.append('X-Tags', 'b')
console.log(headers.get('X-Tags')) // 'a, b'

Understanding Headers.prototype.append

The Headers.prototype.append method in JavaScript appends a new value onto an existing header inside a Headers object, or adds the header if it does not already 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.append(name, value). It accepts 2 parameters: name, value. When called, it returns undefined. Understanding when and how to use append() helps you write more expressive, readable code.

Common use cases for Headers.prototype.append 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-get, fetch-headers-delete, enabling you to chain operations together for complex data manipulation pipelines.

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