Headers:delete() 方法
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
Headers
接口的 delete()
方法可以从当前 Headers
对象中删除指定标头。
下列原因将会导致该方法抛出 TypeError
:
- name 参数的值不是 HTTP 标头的名称。
- Guard 的值为
immutable
。
语法
js
delete(name)
参数
name
-
你想要从
Headers
对象中删除的 HTTP 标头的名称。
返回值
无(undefined
)。
示例
创建一个空的 Headers
对象很简单:
js
const myHeaders = new Headers(); // 目前为空
你可以通过 Headers.append
方法添加标头:
js
myHeaders.append("Content-Type", "image/jpeg");
myHeaders.get("Content-Type"); // 返回 'image/jpeg'
然后你可以删除它。
js
myHeaders.delete("Content-Type");
myHeaders.get("Content-Type"); // 返回 null,因为它已被删除
规范
Specification |
---|
Fetch # ref-for-dom-headers-delete① |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
delete |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.