2

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

7

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

@Nick, not really, I feel like it's ironic to see someone getting annoyed about something so insignificant
4

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.