# Disable the Set iterator APIs (`ts-compat/no-set-iterator`) A Set built on iterators is slow: every `entries`, `keys` or `values` call allocates an iterator object, and `for...of` and spread walk it one step at a time. When the hot path needs the fastest possible set, the code targets IE 11, whose native Set has no iterator at all, so only what IE 11 provides stays allowed: `forEach`, `add`, `has`, `delete`, `clear` and `size`. This rule bans `entries`, `keys`, `values` and `Symbol.iterator` on a Set, and bans `for...of` and spread over a Set. The iterator methods need Chrome 38, Edge 12, Firefox 24, Safari 8, Opera 25 or iOS Safari 8 to run and the `@@iterator` protocol needs Chrome 43, Firefox 36, Safari 9, Opera 30 or iOS Safari 9, while no version of IE has either, even though IE 11 supports the Set itself and `forEach`. ## Rule Details Examples of **incorrect** code for this rule: ```ts const s = new Set(["a", "b"]); for(const value of s.entries()) { console.log(value); } for(const value of s.keys()) { console.log(value); } for(const value of s.values()) { console.log(value); } const it = s[Symbol.iterator](); for(const value of s) { console.log(value); } const array = [...s]; console.log(it, array); ``` Examples of **correct** code for this rule: ```ts const s = new Set(["a", "b"]); s.forEach(value => { console.log(value); }); s.add("c"); const has = s.has("c"); console.log(s.size, has); s.delete("c"); s.clear(); ``` ## When Not To Use It * The code does not need IE 11, or the Set iteration is not performance critical. * Iterating a Set without `forEach` is clearer, such as a spread to sort the values. ## Further Reading * [MDN Set.prototype.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach) * [MDN Set.prototype.entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)