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 ?
Nos followed by oneYes.if.presentvar in your anser, justif (i < find.length)will work: you're using a break statement, if that break is never encountered, i === find.length, else, it'll always be smaller. nitpicking, I know, but I like to use as little vars as possible