Headers:has() 方法
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.
备注: 此特性在 Web Worker 中可用。
Headers
接口的 has()
方法返回一个布尔值来声明一个 Headers
对象是否包含特定的标头。
语法
js
has(name)
参数
返回值
一个布尔值。
示例
创建一个空的 Headers
对象非常简单:
js
const myHeaders = new Headers(); // 当前为空
你可以使用 Headers.append
来添加一个标头,然后使用 has()
方法来测试是否添加成功:
js
myHeaders.append("Content-Type", "image/jpeg");
myHeaders.has("Content-Type"); // 返回 true
myHeaders.has("Accept-Encoding"); // 返回 false
规范
Specification |
---|
Fetch # ref-for-dom-headers-has① |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
has |
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.