I am faced with a challenge involving three arrays. One array contains static values, another array contains dynamic values, and the third array is intended to store values that are present in both of the other arrays.
My goal is to iterate through the arrays and identify matching values. When a match is found, that value should be added to a separate array.
This is what I am aiming for:
Array1 = ["Store1", "Store2", "Store3", "Store4"];
Array2 = ["Store6", "Store1", "Store3", "Store999"];
MatchedArray = ["Store1", "Store3"]; // should contain these values
However, I am not keen on using nested 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 explore alternative methods such as using the .map or filter function to achieve this task.