I am new to JavaScript and i will appreciate some help . I try to search array for element but i cant find the right solution . First i tried this , but no success.
var find = function(string, array) {
for(i=0;i>=array.length-1;i++){
if(array[i]==string){
return true;
}
else{
return false;
}
}
};
Then i tried this
var find = function(string, array) {
if(array.indexOf(string)>-1){
return true;}
else{
return false;
}
};
but it doesn't work with numbers This are my tests
Test.assertEquals(find("hello", ["bye bye","hello"]), true);
Test.assertEquals(find("2", ["bye bye","2"]), true);
Test.assertEquals(find("2", ["bye bye",2]), false);