Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
docs Merge remote-tracking branch 'core-js/map-find' Sep 4, 2018
spec Merge remote-tracking branch 'core-js/map-find' Sep 4, 2018
test/set 'New' proposal Jan 27, 2018
.gitignore add `Map.prototype.{some, every}` Jul 3, 2018
LICENSE Minor fix for links/typos Jan 31, 2018
README.md Merge remote-tracking branch 'core-js/map-find' Sep 4, 2018
map-polyfill.js 'New' proposal Jan 27, 2018
package-lock.json Fixed vuln. dependencies Jul 3, 2018
package.json Fixed vuln. dependencies Jul 3, 2018


New collections (Set and Map) methods

See formal spec WIP.

(Semi)relevant previous discussions


  • it's consistent with already familiar and widely used Array API (reduced cognitive overhead)
    • easier refactoring
    • certain function become generic
  • reduces boilerplate code when dealing with common collection use cases
  • no new syntax
  • allow developers coming from other languages to use familiar APIs



Quick reference for other languages similar data structures


Map (known also as Dictionary)



This proposal does not change grammar of language.

New methods are added to Set.prototype.

  • Array-like methods. These methods replicates functionality of Array.prototype methods:
    • Set.prototype.filter(predicate, thisArg)
    • Set.prototype.map(fn, thisArg)
    • Set.prototype.find(fn, thisArg)
    • Set.prototype.reduce(fn, initialValue)
    • Set.prototype.join(separator)
    • Set.prototype.some(predicate, thisArg)
    • Set.prototype.every(predicate, thisArg)
  • New methods:
    • Set.prototype.addAll(...elements) - similar to Array.prototype.push. Adds all of arguments to existing Set.
      • Alternative name: .addEach
    • Set.prototype.deleteAll(...elements) - reverse of addAll. Remove every element in elements from existing Set.
      • Alternative names: .deleteEach

New methods are added to Map.prototype.

  • Array-like methods. These methods replicates functionality of Array.prototype methods:

    • Map.prototype.filter(predicate, thisArg)
    • Map.prototype.mapValues(fn, thisArg)
    • Map.prototype.mapKeys(fn, thisArg)
    • Map.prototype.reduce(fn, initialValue)
    • Map.prototype.find(fn, thisArg)
    • Map.prototype.findKey(fn, thisArg)
    • Map.prototype.keyOf(searchElement)
    • Map.prototype.some(predicate, thisArg)
    • Map.prototype.every(predicate, thisArg)
    • Map.prototype.includes(searchElement)
  • New methods:

    • Map.prototype.deleteAll(...elements) - similar to Set.prototype.deleteAll.
    • Map.prototype.merge(iterable) - performs in-place update joining two maps.

New methods are added to %Map%.

  • Map.groupBy -
  • Map.keyBy -

New methods are added to WeakSet.prototype.

  • New methods:
    • WeakSet.prototype.addAll(...elements) - similar to Set.prototype.addAll.
    • WeakSet.prototype.deleteAll(...elements) - similar to Set.prototype.deleteAll.

New methods are added to WeakMap.prototype.

  • New methods:
    • WeakMap.prototype.deleteAll(...elements) - similar to Map.prototype.deleteAll.

Not included in this proposal but worth considering

  • Set.prototype.isSubsetOf(otherSet)
  • Set.prototype.isSupersetOf(iterable)
  • Set.prototype.flatMap, Set.prototype.flat - should be added if Array.prototype.flatMap is added to language

Why not %IteratorPrototype% methods

  • Explicit usage of iterators is verbose
    • Compare new Set(set.entries().filter(fn)) to set.filter(fn). 19 characters of boilerplate.
      • Even small codebase can have hundreds occurrences of this pattern - and hundreds places to make a mistake.
  • User code have no easy way to inherit from %IteratorPrototype%