jQuery has a utility function for this:
$.inArray(value, array)
Returns index of value
in array
. Returns -1
if array
does not contain value
.
See also How do I check if an array includes an object in JavaScript?
More Related Contents:
- How to check if a string contains text from an array of substrings in JavaScript?
- compare each 5 numbers of two array [closed]
- Convert string into several integer arrays [duplicate]
- How to get all the values associated with an object in array?
- Sort array of objects by string property value
- Best way to manage Chat channels in Firebase
- Group array of object nesting some of the keys with specific names
- How to sort 2 dimensional array by column value?
- JQuery .each() backwards
- Why does javascript’s “in” operator return true when testing if 0 exists in an array that doesn’t contain 0?
- Add property to an array of objects
- How to update an “array of objects” with Firestore?
- Reverse array in Javascript without mutating original array
- Sorting objects by property values
- Razor MVC Populating Javascript array with Model Array
- Fastest JavaScript summation
- How to find duplicate values in a JavaScript array of objects, and output only unique values?
- Using promise function inside Javascript Array map
- Javascript passing arrays to functions by value, leaving original array unaltered
- What does $(selector)[0] mean in jQuery?
- Get list of duplicate objects in an array of objects
- Change the value of an array changes original array JavaScript
- Returning only certain properties from an array of objects in Javascript [duplicate]
- Sum two arrays in single iteration
- Array.size() vs Array.length
- Create array of all integers between two numbers, inclusive, in Javascript/jQuery
- What is the difference between “in operator” and “includes()” for JavaScript arrays
- Sorting an Array of JavaScript Objects a Specific Order (using existing function)
- Find last index of element inside array by certain condition
- How to flatten array in jQuery?