ES6 - 集合 Set 方法 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 
廣告
© . All rights reserved.