Skip to content

Instantly share code, notes, and snippets.

@gh640
Created December 14, 2013 03:48
Show Gist options
  • Save gh640/7955465 to your computer and use it in GitHub Desktop.
Save gh640/7955465 to your computer and use it in GitHub Desktop.
JavaScript function to check 2 arrays have any common element or not. return true or false.
// function to check 2 arrays have any common element or not
// @return
// matched : true/false
// @args
// a1 :: array
// a2 :: array
function commonElementExist(a1, a2){
var matched = false;
a1.forEach(function(e1){
if(a2.indexOf(e1) != -1){
matched = true;
return false;
}
});
return matched;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment