Safe code for new Set() may look like:
let items = [];
for (let item of set)
if (isBad(item))
items.push(item);
for (let item of items)
s
Yes, you can simplify to that, it's totally safe.
From that last point follows that the only dangerous thing to do would be something like
const s = new Set([1]);
for (let x of s) {
s.delete(x);
s.add(1);
}
but not because of undefined behaviour or memory accumulation, but because of the infinite loop.