How it works...

An intersection of two sets is defined as all the elements that appear in both sets. In this recipe, we use the has method to implement an intersection operation. We loop over the elements of the first Set and check whether the second contains each element. If the second Set contains that element, then the has method will return true. If this method returns true, then we know that the element is in both Set instances, and we add it to the new intersection.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.