jQuery .inArray() always true?

If you are facing problem in jquery .inArray() function giving always true then use below code:

1
2
3
4
5
if( $.inArray('Aqua', arrVals) > -1 ) {

or this:

if( $.inArray('Aqua', arrVals) !== -1 ) {

The $.inArray() method returns the 0 based index of the item. If there’s no item, it returns -1, which the if() statement will consider as true.

Leave a Reply