I have three arrays. One with static values, the other one has dynamic values, one array which will be filled with values that are the equal in the two arrays.
I would like to loop through the arrays and search for equal values. When a equal value has been found, this value should be put inside another array.
Something like this:
Array1 = ["Store1", "Store2", "Store3", "Store4"];
Array2 = ["Store6", "Store1", "Store3", "Store999"];
MatchedArray = ["Store1", "Store3"]; // should be filled with this
However, I don't like the idea of two for loops, like this:
for(var arr1 = 0; arr1 < Array1.length; i++){
for(var arr2 = 0; arr2 < Array2.length; i++){
if(Array1[arr1].toLowerCase() == Array2[arr2].toLowerCase(){
console.log('store found');
duplicateArray.push(Array1[i].toLowerCase());
}
}
}
I would like to know how I can use the .map or filter function or some other ways to accomplish this.