ES6 - 集合设置方法 forEach

此函数对每个 Map 条目执行一次指定的函数。

语法

myMap.forEach(callback[, thisArg])

参数

  • callback − 为每个元素执行的函数。

  • thisArg − 执行回调时用作 this 的值。

返回值

未定义。

示例

function userdetails(values) { 
   console.log(values); 
}  
var mySet = new Set(); 
mySet.add("John"); 
mySet.add("Jane"); 
mySet.forEach(userdetails); 

输出

John 
Jane