filter() এবং includes() মেথড ব্যবহার করে সহজেই দুটি অ্যারের সাধারণ উপাদানগুলো বের করা যায়।
উদাহরণ
var firstNamesArray = ["John", "David", "Bob", "Sam", "Carol"];
var secondNamesArray = ["Mike", "Carol", "Adam", "David"];
var 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' ]