When I run the code provided below, I am getting a different answer depending on whether the else statement is included or not. Without the else statement, the answer is true, but with the else statement it is false. Can anyone explain why this is happening?
function search(arr, item) {
for (let i=0; i < arr.length; i++){
if (arr[i] == item){
return true;
}
else{
return false;
}
}
}
result = search([6, 2, 3, 4], 3);
console.log(result);