Reputation: 7156
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.
Upvotes: 3
Views: 4765
Reputation: 189
You can also use:
var result = [];
for(i=0;i<listdata.names.length;i++){
var n = listdata.names[i].toLocaleLowerCase();
var s = x('input').value.toLocaleLowerCase();
if(n.indexOf(s) != -1){result.push(listdata.names[i]);}
}
This way we can output an result from an input value and existing array of values.
Little typicall to understand but..... :)
Upvotes: 0