I'm trying to make a third array out of two arrays. I want to check if array 2 contains array 1 elements.
So Array2 could look like:
["Bol Sales ", "BookStore Amazon Sales", "Nintendo Sales", "XBOX" ]
Array 1:
["Bol", "Amazon","XBOX"]
Array 3 should then be:
["Bol", "Amazon", "XBOX"]
But most of the outcomes are only XBOX (so, array1.val full match array2.val).
I've tried the following:
var array1 = ["Bol", "Amazon", "XBOX"],
array2 = ["Bol Sales ", "BookStore Amazon Sales", "Nintendo Sales", "XBOX"],
array3 = [];
array3 = array1.filter(function(store) {
return array2.includes(store);
});
console.log(array3);
array3 = array1.filter(function(store) {
return array2.indexOf(store) >= 0;
});
console.log(array3);
var storesToCheck = function(array1, array2) {
return array1.some(function(value) {
return array2.indexOf(value) >= 0;
});
};
console.log(storesToCheck(array1, array2));