urlSearchParams.forEach(fn[, thisArg])


  • fn <Function> 为查询中的每个名称-值对调用
  • thisArg <Object> 在调用 fn 时用作 this

迭代查询中的每个名称-值对并调用给定的函数。

const myURL = new URL('https://example.org/?a=b&c=d');
myURL.searchParams.forEach((value, name, searchParams) => {
  console.log(name, value, myURL.searchParams === searchParams);
});
// 打印:
//   a b true
//   c d true
  • fn <Function> Invoked for each name-value pair in the query
  • thisArg <Object> To be used as this value for when fn is called

Iterates over each name-value pair in the query and invokes the given function.

const myURL = new URL('https://example.org/?a=b&c=d');
myURL.searchParams.forEach((value, name, searchParams) => {
  console.log(name, value, myURL.searchParams === searchParams);
});
// Prints:
//   a b true
//   c d true