urlSearchParams.forEach(fn[, thisArg])


  • fn <Function> 在查询字符串中的每个键值对的调用函数。
  • thisArg <Object>fn调用时,被用作this值的对象

在查询字符串中迭代每个键值对,并调用给定的函数。

const { URL } = require('url');
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