Skip to content

Set Helpers

Utility functions for working with set operations.

FunctionDescription
countByGroups the values of a Set by a derived key and counts how many fall into each group.
differencenative JS Set.prototype.difference() (ES2025 (Set methods))
filterCreates a new Set containing only the values for which the predicate returns true.
forEachnative JS Set.prototype.forEach((value, value2, set) => ...) (ES2015)
groupBynative JS Map.groupBy(set.values(), fn) (ES2024)
intersectionnative JS Set.prototype.intersection() (ES2025 (Set methods))
mapCreates a new Set with each value transformed by a function.
map / filternative JS new Set(set.values().map(fn)) / new Set(set.values().filter(fn)) (ES2025 (Iterator Helpers))
reduce / some / every / findnative JS set.values().reduce(fn, init) / .some(fn) / .every(fn) / .find(fn) (ES2025 (Iterator Helpers))
symmetricDifferencenative JS Set.prototype.symmetricDifference() (ES2025 (Set methods))
toMapByKeyBuilds a Map from a Set, keyed by a derived key.
unionnative JS Set.prototype.union() (ES2025 (Set methods))