I have 2 string arrays:
var X = ['A', 'B', 'C'],
Y = ['B', 'C', 'D'];
I need to create an array Z
, such that Z = A ∩ B
Z = ['B', 'C'];
Z contains the strings that are both in X
and Y
.
I've done it this way:
A.forEach(function(i) {
B.forEach(function(j) {
if (i === j) Z.push(i);
});
});
Any suggestions / comments?