Loading topic
union, intersection, difference, and the rest) all build on three behaviours that Set has always had. A Set stores only unique values. It decides uniqueness with an algorithm called SameValueZero. It remembers the order in which values were inserted. This chapter3 min readSet, call add, has, and delete on it, and know the difference between an object reference and a primitive value. Before looking at each composition method on its own, it helps to learn the one rule they all follow: **they never change the sets you call t2 min readSet, add values with add, check them with has, and iterate with for...of. It also assumes you know spread syntax ([...set]). The union method arrived in ES2025. It ships in current versions of Chrome, Edge, Firefox, Safari, and Node.js 22 and later.2 min readhas on it, and iterate it with for...of. It also assumes you know from the previous chapter that Set methods return a new Set and leave both inputs unchanged.2 min readSet, and that you know union and intersection return a new Set without changing their inputs. Here we cover difference, the one basic set operation where the order of the two sets changes the answer.3 min readfor...of, and that you understand spread syntax. You should also have read the earlier chapters on union, intersection, and difference, because symmetricDifference builds on all three.2 min readunion, intersection, difference) each build a new Set. Sometimes you only need a yes-or-no answer about how two sets relate. ES2025 adds three predicate methods for that. Each one returns a boolean and creates no new Set.3 min readhas, that you have used intersection and difference, and that you understand the difference between primitive values and object references. Here we look at what happens when the elements of a Set are objects rather than strings or numbe2 min readSet iterates in insertion order and that you have already seen union, intersection, difference, and symmetricDifference in earlier chapters. The focus here is narrower: when you spread a result into an array or loop over it, which element comes first?2 min readSet, have used Map, and understand how iterators work, including next() and Symbol.iterator. It also builds on the union, intersection, and difference methods from earlier chapters.2 min readArray.prototype.filter, and typeof checks. It covers where the methods are available, how to check for them at runtime, and how to write fallbacks that behave like t3 min readunion, intersection, difference, symmetricDifference, and the predicates isSubsetOf, isSupersetOf, and isDisjointFrom. It also assumes you are comfortable with Array.prototype.filter and map. The examples ru2 min read