How Get the Intersection of two Sets using JavaScript

 

The program to get intersection or common elements between two arrays 

 

 




 const setA = new Set([1,3,4,5,6]);
 const setB = new Set([3,5,9,0,1]);

    let result = [];

    for (let i of setB) {
    
        if (setA.has(i)) {
            result .push(i);
        }
        
    }
    
console.log(result);

Tags:

Share:

Related posts