उदाहरण
filter() और includes() का उपयोग करके दो ऐरे का इंटरसेक्शन निकालें।
var firstNamesArray = ["John", "David", "Bob", "Sam", "Carol"];
var secondNamesArray = ["Mike", "Carol", "Adam", "David"];
var intersectionOfArray = [];
intersectionOfArray = firstNamesArray.filter(v => secondNamesArray.includes(v));
console.log("Intersection of two array=");
console.log(intersectionOfArray);
प्रोग्राम चलाने के लिए:
node fileName.js
आउटपुट
PS C:\Users\Amit\JavaScript-code> node demo141.js Intersection of two array= [ 'David', 'Carol' ]