此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Headers.entries()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2017年10月⁩.

Headers.entries()迭代器的形式返回 Headers 对象中所有的键值对。每一对中的键和值都是 String 对象。

备注: 这个方法在 Web Worker 中是可用的。

语法

js
entries()

参数

无。

返回值

返回一个迭代器

示例

js
// 创建一个测试 Headers 对象
const myHeaders = new Headers();
myHeaders.append("Content-Type", "text/xml");
myHeaders.append("Vary", "Accept-Language");

// 显示键/值对
for (const pair of myHeaders.entries()) {
  console.log(`${pair[0]}: ${pair[1]}`);
}

运行结果为:

content-type: text/xml
vary: Accept-Language

浏览器兼容性

参见