Headers.get(), append(), set(), has(), delete()
new Headers(init)
Headers.prototype.get(name)
Headers.prototype.append(name, value)
Headers.prototype.set(name, value)
Headers.prototype.has(name)
Headers.prototype.delete(name)
Headers.prototype.entries()Read and write headers with case-insensitive names, merging values with append and replacing them with set.
| Parameter | Description |
|---|---|
init | An object, an array of pairs, or another Headers object. |
name, value | The header name and value. Names are matched case-insensitively. |
Returns: get returns a string or null. has returns a boolean. entries yields lowercase name/value pairs.
const headers = new Headers({ "Content-Type": "text/plain", "X-A": "1" });
headers.append("X-A", "2");
headers.set("x-b", "B");
console.log(headers.get("content-type"));
console.log(headers.get("X-A"));
console.log(headers.get("x-a"));
console.log(headers.has("CONTENT-TYPE"));
console.log(JSON.stringify([...headers.entries()]));
headers.set("X-A", "only");
console.log(headers.get("x-a"));
headers.delete("x-b");
console.log(headers.has("x-b"));
Expected output
text/plain
1, 2
1, 2
true
[["content-type","text/plain"],["x-a","1, 2"],["x-b","B"]]
only
false
Related: Request and Response