Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
What's the best way to compare two Javascript arrays and create a new array of only the matches?
var a = ["a","m"],
b = ["a","c","x","l","m"] ,
c = [], //array with matches
i = a.length,
j;
while(i--) {
j = b.length;
while (j--) {
if (b[j] == a[i]) {
c.push(a[i]);
}
}
}
console.log(c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.