I have this:
$.inArray(tld, tldsArray)
I would like to check if tld is NOT on the array. How can we say this on jQuery?
Christian C. Salvadó
831k185 gold badges929 silver badges845 bronze badges
asked Nov 3, 2010 at 17:37
2 Answers 2
See if the result is -1
like this:
if($.inArray(tld, tldsArray) == -1) {
//not in the array
}
You should not use if(!$.inArray(tld, tldsArray))
since $.inArray()
returns the position in the array, including 0
if it's the first element.
answered Nov 3, 2010 at 17:39
Sign up to request clarification or add additional context in comments.
1 Comment
Luca Matteis
@Nick, not really, I feel like it's ironic to see someone getting annoyed about something so insignificant
As stated in the documentation, the inArray
method returns -1
when the element is not found in the array. So simply test the returned value against -1
.
answered Nov 3, 2010 at 17:40
Comments
lang-js