URLSearchParams:entries() 方法

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

备注: 此特性在 Web Worker 中可用。

URLSearchParams 接口的 entries() 方法返回一个用于遍历该对象中包含的所有键/值对的迭代器。迭代器按照查询字符串中出现的顺序返回键/值对,每一组键和值都是字符串对象。

语法

js
entries()

参数

无。

返回值

返回一个 iterator

示例

js
// 创建一个测试用的 URLSearchParams 对象
const searchParams = new URLSearchParams("key1=value1&key2=value2");

// 显示键/值对
for (const [key, value] of searchParams.entries()) {
  console.log(`${key}, ${value}`);
}

结果如下:

key1, value1
key2, value2

规范

Specification
URL
# dom-urlsearchparams-urlsearchparams

浏览器兼容性

参见

  • URL 接口。