# Disable the Map iterator APIs (`ts-compat/no-map-iterator`) A Map 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 map, the code targets IE 11, whose native Map has no iterator at all, so only what IE 11 provides stays allowed: `forEach`, `get`, `set`, `has`, `delete`, `clear` and `size`. This rule bans `entries`, `keys`, `values` and `Symbol.iterator` on a Map, and bans `for...of` and spread over a Map. The iterator methods and the `@@iterator` protocol need Chrome 38, Edge 12, Firefox 36, Safari 10, Opera 25 or iOS Safari 10 to run, and no version of IE has them, while IE 11 supports the Map itself and `forEach`. ## Rule Details Examples of **incorrect** code for this rule: ```ts const m = new Map([["a", 1]]); for(const [key, value] of m.entries()) { console.log(key, value); } for(const key of m.keys()) { console.log(key); } for(const value of m.values()) { console.log(value); } const it = m[Symbol.iterator](); for(const entry of m) { console.log(entry); } const array = [...m]; console.log(it, array); ``` Examples of **correct** code for this rule: ```ts const m = new Map([["a", 1], ["b", 2]]); m.forEach((value, key) => { console.log(key, value); }); m.set("c", 3); const value = m.get("c"); const has = m.has("c"); console.log(m.size, value, has); m.delete("c"); m.clear(); ``` ## When Not To Use It * The code does not need IE 11, or the Map iteration is not performance critical. * Iterating a Map without `forEach` is clearer, such as a spread to sort the entries. ## Further Reading * [MDN Map.prototype.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach) * [MDN Map.prototype.entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)