无涯教程-Set.prototype.forEach(callbackFn[, thisArg])函数

34 阅读1分钟

该函数对每个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 

参考链接

www.learnfk.com/es6/es6-set…