该函数对每个Map元素执行一次。
Set.prototype.forEach(callbackFn[, thisArg]) - 语法
myMap.forEach(callback[, thisArg])
callback - 为每个元素执行的功能。
thisArg - 执行回调时用作此值。
function userdetails(values) { console.log(values); } var mySet=new Set(); mySet.add("John"); mySet.add("Jane"); mySet.forEach(userdetails);
运行上面代码输出
John Jane