Headers.prototype.delete
Deletes a header from a Headers object
Syntax
headers.delete(name)Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | The name of the HTTP header to delete |
Return Value
undefined
Examples
const headers = new Headers({ 'Authorization': 'Bearer token', 'Accept': '*/*' })
headers.delete('Authorization')
console.log(headers.has('Authorization')) // falsefunction sanitizeHeaders(headers: Headers) {
const remove = ['X-Debug', 'X-Internal']
remove.forEach(h => headers.delete(h))
}const headers = new Headers()
headers.set('X-Custom', 'value')
headers.delete('X-Custom')
console.log([...headers.keys()]) // []Understanding Headers.prototype.delete
The Headers.prototype.delete method in JavaScript deletes a header from a 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.delete(name). It accepts 1 parameter: name. When called, it returns undefined. Understanding when and how to use delete() helps you write more expressive, readable code.
Common use cases for Headers.prototype.delete 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-has, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Headers.prototype.delete 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.setSets a new value for an existing header inside a Headers object, or adds the header if it does not already exist
Headers.prototype.getReturns the value of the specified header from a Headers object, or null if it does not exist
Headers.prototype.hasReturns whether a Headers object contains a certain header
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.