URLSearchParams.forEach()

翻译不完整。 请帮助我们翻译这篇文章!

   URLSearchParams的实例对象上的方法forEach允许通过回调函数来遍历URLSearchParams实例对象上的键值对

Note: 此特性在 Web Worker 中可用。

语法

searchParams.forEach(callback(value,key,searchParams));

参数

回调函数
    该回调函数可以接收到3个参数value,key,searchParams,我们可以在回调函数中对接收到的参数进行处理。而三个参数的含义如下:
    1.  value
     当前遍历到的键值
    2.  key
     当前遍历到的键名
    3.  searchParams
     当前调用forEach方法的实例对象

返回值

    空

例子

// 创建URLSearchParams对象的实例对象,用于测试
var searchParams = new URLSearchParams("key1=value1&key2=value2");

let returnValue = searchParams.forEach(function(value, key,searchParams) {
     // 打印值  
     console.log(value, key,searchParams);
});

// 输出返回值
console.log(returnValue)

结果是:

value1 key1 当前调用forEach方法的实例对象(也就是searchParams)
value2 key2 当前调用forEach方法的实例对象(也就是searchParams)
undefined  // 即没有返回值

Specifications

Specification Status Comment
URL
forEach() (see "iterable")
Living Standard Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
forEachChrome Full support 49Edge Full support 17Firefox Full support 44IE No support NoOpera Full support 36Safari Full support YesWebView Android Full support 49Chrome Android Full support 49Firefox Android Full support 44Opera Android Full support 36Safari iOS Full support YesSamsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support

See also

  • The URL interface.