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 March 2017.

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

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
entries

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见