Is there possibility of using .indexOf function with an array to search with? Like This:
var d = "Hello";
var s = new Array ("Heart", "David", "Foo", "Hello");
if( d.indexOf(s) != -1) {
alert("Found Hello");
}
If I use above code then it does not alert anything. I checked console but no errors.
I read somewhere that .indexOf function is for strings only not for array of string.
Is there alternative of indexOf in Javascript or .indexOf already provides what i want?
You should be calling the method on the object you wish to search not on the item which you wish to search for,
s.indexOf(d)in your case