inArray
returns the index of the element in the array, not a boolean indicating if the item exists in the array. If the element was not found, -1
will be returned.
So, to check if an item is in the array, use:
if(jQuery.inArray("test", myarray) !== -1)
More Related Contents:
- ReferenceError: event is not defined
- Which is the fastest way to loop? [for curiosity]
- Jquery replace only specific characters [closed]
- SecurityError: Blocked a frame with origin from accessing a cross-origin frame
- window.onload vs $(document).ready()
- How to resize images proportionally / keeping the aspect ratio?
- Is there a null-coalescing (Elvis) operator or safe navigation operator in javascript?
- Remove ALL white spaces from text
- Method overloading in Javascript
- Select all contents of textbox when it receives focus (Vanilla JS or jQuery)
- In jQuery, how do I select an element by its name attribute?
- Equivalent of jQuery .hide() to set visibility: hidden
- JQuery .on() method with multiple event handlers to one selector
- How can I update window.location.hash without jumping the document?
- Prevent contenteditable adding on ENTER – Chrome
- jQuery.parseJSON vs JSON.parse
- Multi-line string insert using jQuery
- Why is ‘event’ available globally in Chrome but not Firefox?
- Possible to associate label with checkbox without using “for=id”?
- Waiting on multiple asynchronous calls to complete before continuing
- Moving a focus when the input text field reaches a max length
- How to scroll to an element in jQuery?
- Web browser: Hide mouse cursor [duplicate]
- Changing the page title with Jquery
- How to create a new img tag with JQuery, with the src and id from a JavaScript object?
- How to iterate a table rows with JQuery and access some cell values?
- DOM Element Width before Appended to DOM
- How to stop user from printing webpages? using javascript or jquery
- How can I compare two color values in jQuery/JavaScript?
- How to avoid conflict between JQuery and Prototype