Is there a way to create a process where the first loop iterates through the elements of one array, while another loop goes through a second array and compares each element in the first array with all elements in the second array?
For example: //first loop iterating through array1
for (var i = 0; i < array1.length; i++) {
//storing the current element
var test = array1[i]
//second loop iterating through array2
for (var j = 0; j < array2.length; j++) {
//comparing the current element from array1 to all elements in array2
if (test == array2[j]) {
alert(array2[j])
}
}
}
Essentially, I am looking to have the first loop compare each element of array1 to every element in array2 before moving on to the next element in array1. However, when I run this code, it seems to only keep alerting the first element of array 1 repeatedly.