forEach < Set < JavaScript
The forEach() method of a Set executes a provided function once for each value in this set, in insertion order.
const numbers = new Set([2, 3, 5, 7]);
const primes = [];
function square(number) {
const sq = number * number;
primes.push(sq);
}
numbers.forEach(square)
primes.forEach(function(number) {
console.log(number);
});
// 4
// 9
// 25
// 49