Syntax error What is the easiest code for array intersection in JavaScript?

What is the easiest code for array intersection in JavaScript?



For array intersection, you can try to run the following code in JavaScript −

Example

<html>
   <body>
      <script>
         let intersection = function(x, y) {
            x = new Set(x), y = new Set(y);
            return [...x].filter(k => y.has(k));
         };

         document.write(intersection([5,7,4,8], [3,9,8,4,3]));
      </script>
   </body>
</html>
Updated on: 2020-06-23T13:03:41+05:30

123 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements