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.
メモ: この機能はウェブワーカー内で利用可能です。
has()
は Headers
インターフェイスのメソッドで、 Headers
オブジェクトに指定された特定のヘッダーがあるかどうかを示す論理値を返します。
セキュリティ上の理由から、いくつかのヘッダーはユーザーエージェントでしか制御できません。これには、禁止ヘッダー名と禁止レスポンスヘッダー名があります。
構文
js
has(name)
引数
返値
論理値です。
例
空の Headers
オブジェクトを作成するのは簡単です。
js
const myHeaders = new Headers(); // Currently empty
これに Headers.append
を使用してヘッダーを追加し、has()
を使用してヘッダーが存在するかどうかをテストすることができます。
js
myHeaders.append("Content-Type", "image/jpeg");
myHeaders.has("Content-Type"); // Returns true
myHeaders.has("Accept-Encoding"); // Returns 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.