intersection

var arr1 = [2, 3, 4, 5, 6, 7];
      var arr2 = [3, 4, 5, 8, 9];

      let arr3;
      arr3 = arr1.filter(function (num) {
        return arr2.indexOf(num) != -1;
      });

      document.write(arr3);
Copy the code

Using filter, return the elements that meet the criteria

The num parameter refers to arr1,

Determine the presence of an element using indexOf equal to -1.

indexOf ! =-1 means that you can find elements of ARR2 in num.

And set

  let arr4;
      arr4 = arr1.concat(arr2);
      function unique(arr) {
        return Array.from(new set(arr));
      }

      document.write(unique(arr4));
Copy the code

Concat is used to concate two arrays, then set is used to deduplicate them.