What is the simplest way too check is some element presence to array?
I have following code:
var val = "1";
var arr = ["1", "2"];
if($.inArray(val, arr)) {
console.log("I am in!")
} else {
console.log("I am NOT here :( ")
}
but it prints “1” is NOT at [“1”, “2”] array! Please open my eyes – what is the problem here?
The
$.inArrayreturns index of the matched element position which can range from0to(length - 1). So you should>= 0as it is the first element it will be returning the index as0.