I have an array in javascript and a variable as follows:
var numArr = ["one", "two", "three"];
var searchNum = "four";
I want to search “four” in numArr and if not present then execute some statements… as in
if (searchNum not in numArr)
{
// do this
}
Does javascript have any function which could search in any array and return true or false without me writing a whole lot of search code.
Use
indexOf:The method will return -1 if it fails to find
searchNum. Otherwise it will return the index at which it found it.