Hi, I have these two examples to compare two arrays with each other to find matches. I wanted to know which option would be more successful and readable.
const colorsOne = ["Blue", "Green", "Red"];
const colorsTwo = ["Blue", "Black"];
let color = false;
// First Example
for(i = 0; i < colorsOne.length; i++){
const search = colorsTwo.indexOf(colorsOne[i]);
if(search >= 0){
color = true;
}
}
// Second Example
for(i = 0; i < colorsOne.length; i++){
for(j = 0; j < colorsTwo.length; j++){
if(colorsOne[i] == colorTwo[j]){
color = true;
}
}
}