I have a sample code:
var find = ['iphone 3', 'iphone 4', 'iphone 5'];
var search = 'iphone 5';
for(i=0; i<find.length; i++) {
if(search == find[i]) {
alert('Yes');
} else {
alert('No');
}
}
When I run code, result 2 alert(alert('Yes') and alert('No')), but result exactly is only a alert('Yes'), how to fix it ?
If I understand your question correctly, you don’t want
noto be alerted when there is no match found:Just don’t provide the
elsebranch. Oh, and if you don’t care about older browsers: