Skip to content

Map Helpers

Utility functions for working with map operations.

FunctionDescription
countByGroups the entries of a Map by a derived key and counts how many fall into each group.
everyChecks if every entry of a Map satisfies the predicate.
filterCreates a new Map containing only the entries for which the predicate returns true.
findKeyReturns the first key of a Map whose entry satisfies the predicate, in insertion order.
findKey / findValuenative JS map.entries().find(([k, v]) => pred(v, k))?.[0 or 1] (ES2025 (Iterator Helpers))
findValueReturns the first value of a Map whose entry satisfies the predicate, in insertion order.
forEachnative JS Map.prototype.forEach((value, key, map) => ...) (ES2015)
groupBynative JS Map.groupBy(map.entries(), ([k, v]) => groupFn(v, k)) (ES2024)
hasValueChecks whether a value exists anywhere in a Map (`Map.prototype.has` checks keys, not values).
hasValuenative JS map.values().some(v => Object.is(v, value)) (ES2025 (Iterator Helpers))
mapKeysCreates a new Map with the same values but with each key transformed by a function.
mapValuesCreates a new Map with the same keys but with each value transformed by a function.
reduceReduces a Map to a single value by applying a function to each entry, in insertion order.
reduce / some / everynative JS map.entries().reduce(fn, init) / .some(fn) / .every(fn) (ES2025 (Iterator Helpers))
someChecks if at least one entry of a Map satisfies the predicate.
toMapByKeyBuilds a Map from an iterable of items, keyed by a derived key.