Modern browsers have Array#includes, which does exactly that and is widely supported by everyone except IE:

console.log(['joe', 'jane', 'mary'].includes('jane')); // true

You can also use Array#indexOf, which is less direct, but doesn't require polyfills for outdated browsers.

console.log(['joe', 'jane', 'mary'].indexOf('jane') >= 0); // true


Many frameworks also offer similar methods:

  • jQuery: $.inArray(value, array, [fromIndex])
  • Underscore.js: _.contains(array, value) (also aliased as _.include and _.includes)
  • Dojo Toolkit: dojo.indexOf(array, value, [fromIndex, findLast])
  • Prototype: array.indexOf(value)
  • MooTools: array.indexOf(value)
  • MochiKit: findValue(array, value)
  • MS Ajax: array.indexOf(value)
  • Ext: Ext.Array.contains(array, value)
  • Lodash: _.includes(array, value, [from]) (is _.contains prior 4.0.0)
  • Ramda: R.includes(value, array)

Notice that some frameworks implement this as a function, while others add the function to the array prototype.

๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ includes
Array.prototype.includes() - JavaScript | MDN
The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_includes_array.asp
W3Schools.com
The includes() method returns true if an array contains a specified value.
Discussions

What is the correct situation to use array.find() vs. array.includes vs. array.some() ?
const value = arr.find(test) โ€” return the value that passes your test function for when you need to run a test to determine which value you want const bool = arr.some(test) โ€” return true if at least one element passes your test for when you need to see if anything in your array passes your test function const bool = arr.includes(value) โ€” check if a value exists in an array for when you already know the value and you want to check if the array has a copy More on reddit.com
๐ŸŒ r/learnjavascript
7
25
September 14, 2019
Includes vs. In
I tried to use if (!(arr[n][i] in arr[0])){ but I found I had to rewrite the code as if (!(result.includes(arr[n][i]))){ I am having difficulty understanding the difference between the array.includes() function and the ifโ€ฆin syntax. It seems that the ifโ€ฆin syntax is transferable between ... More on forum.freecodecamp.org
๐ŸŒ forum.freecodecamp.org
0
August 18, 2022
JavaScript - include() - A check to see if multiple elements are in an array - Stack Overflow
In the below code, it seems to work, the 3 elements are all in the array so it prints 'yes'. If I take out the last element ("TR"), it prints 'nope'. However, if I take out either of the first 2 elements, it prints 'yes'. It seems to be only focusing on the last element in the includes() function. More on stackoverflow.com
๐ŸŒ stackoverflow.com
(Silly?) inferencing issue/question for Array.includes()
There is a difference between Array and Array | Array (and it's similar with other generics). includes method for the former requires type A | B while for the latter A & B. That's been an issue for years now - don't have a GitHub issue link right now, as I'm on mobile, but should be easily findable. Will post more explanation once I get in front of my PC More on reddit.com
๐ŸŒ r/typescript
12
9
February 9, 2022
Top answer
1 of 16
5530

Modern browsers have Array#includes, which does exactly that and is widely supported by everyone except IE:

console.log(['joe', 'jane', 'mary'].includes('jane')); // true

You can also use Array#indexOf, which is less direct, but doesn't require polyfills for outdated browsers.

console.log(['joe', 'jane', 'mary'].indexOf('jane') >= 0); // true


Many frameworks also offer similar methods:

  • jQuery: $.inArray(value, array, [fromIndex])
  • Underscore.js: _.contains(array, value) (also aliased as _.include and _.includes)
  • Dojo Toolkit: dojo.indexOf(array, value, [fromIndex, findLast])
  • Prototype: array.indexOf(value)
  • MooTools: array.indexOf(value)
  • MochiKit: findValue(array, value)
  • MS Ajax: array.indexOf(value)
  • Ext: Ext.Array.contains(array, value)
  • Lodash: _.includes(array, value, [from]) (is _.contains prior 4.0.0)
  • Ramda: R.includes(value, array)

Notice that some frameworks implement this as a function, while others add the function to the array prototype.

2 of 16
510

Update from 2019: This answer is from 2008 (11 years old!) and is not relevant for modern JS usage. The promised performance improvement was based on a benchmark done in browsers of that time. It might not be relevant to modern JS execution contexts. If you need an easy solution, look for other answers. If you need the best performance, benchmark for yourself in the relevant execution environments.

As others have said, the iteration through the array is probably the best way, but it has been proven that a decreasing while loop is the fastest way to iterate in JavaScript. So you may want to rewrite your code as follows:

function contains(a, obj) {
    var i = a.length;
    while (i--) {
       if (a[i] === obj) {
           return true;
       }
    }
    return false;
}

Of course, you may as well extend Array prototype:

Array.prototype.contains = function(obj) {
    var i = this.length;
    while (i--) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
}

And now you can simply use the following:

alert([1, 2, 3].contains(2)); // => true
alert([1, 2, 3].contains('2')); // => false
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ what is the correct situation to use array.find() vs. array.includes vs. array.some() ?
What is the correct situation to use array.find() vs. ...
September 14, 2019 -

I understand how each of these methods work, but they all seem to have similar functions to one another, and I'm not sure as to what situation might call for what method.

๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ javascript
Includes vs. In
August 18, 2022 - I tried to use if (!(arr[n][i] in arr[0])){ but I found I had to rewrite the code as if (!(result.includes(arr[n][i]))){ I am having difficulty understanding the difference between the array.includes() function and the ifโ€ฆin syntax. It seems that the ifโ€ฆin syntax is transferable between ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-array-includes-method
JavaScript Array includes() Method - GeeksforGeeks
The includes() method in JavaScript is used to check whether an array contains a specific value.
Published ย  January 16, 2026
Find elsewhere
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ javascript-array-contains
JavaScript Array Contains: 6 Methods to Find a Value | Built In
Summary: JavaScript offers multiple methods to check if an array contains a value, including indexOf, includes, some, find and findIndex. While indexOf fails with NaN, includes detects it. Object searches use callback functions with some, find and findIndex. more JavaScript offers multiple methods to check if an array contains a value, including indexOf, includes, some, find and findIndex.
๐ŸŒ
Can I Use
caniuse.com โ€บ array-includes
Array.prototype.includes | Can I use... Support tables for HTML5, CSS3, etc
Determines whether or not an array includes the given value, returning a boolean value (unlike indexOf).
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ array-includes
array-includes - npm
February 6, 2025 - An ES7/ES2016 spec-compliant `Array.prototype.includes` shim/polyfill/replacement that works as far down as ES3.. Latest version: 3.1.9, last published: 9 months ago. Start using array-includes in your project by running `npm i array-includes`. There are 1236 other projects in the npm registry ...
      ยป npm install array-includes
    
Published ย  Jun 02, 2025
Version ย  3.1.9
Author ย  Jordan Harband
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ javascript โ€บ how do i check if an array includes a value in javascript?
How do I check if an array includes a value in JavaScript? | Sentry
There are seven primitive data types: string, number, bigint, boolean, undefined, symbol, and null. Using the includes() method is the most readable method to check if an array contains a primitive value:
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ javascript โ€บ includes-method
JavaScript includes() method: Syntax, Usage, and Examples
The includes() method in JavaScript checks whether a given value exists in a string or array. This functionality is particularly valuable in modern web development when working with data from HTML elements or applying conditional CSS styles.
๐ŸŒ
DEV Community
dev.to โ€บ arnaud โ€บ using-array-prototype-includes-vs-set-prototype-has-to-filter-arrays-41fg
Using Array.prototype.includes() vs Set.prototype.has() to filter arrays - DEV Community
July 2, 2020 - Length of values to keep: 1 Length of values to test: 10 includes: 0.207ms has: 0.190ms Length of values to keep: 10 Length of values to test: 100 includes: 0.020ms has: 0.017ms Length of values to keep: 100 Length of values to test: 1000 includes: 0.204ms has: 0.071ms Length of values to keep: 1000 Length of values to test: 10000 includes: 9.942ms has: 1.307ms Length of values to keep: 10000 Length of values to test: 100000 includes: 131.686ms has: 8.016ms Length of values to keep: 100000 Length of values to test: 1000000 includes: 1324.318ms has: 71.495ms ยท So yes, I am right that with a small quantity of data, Array.includes and Set.has perform roughly the same, but we can see how quickly performance degrades, and the change is so small that it's hard to justify not making it, even for small data samples.
๐ŸŒ
Lodash
lodash.com โ€บ docs
Lodash Documentation
Creates an array of unique values that are included in all given arrays using SameValueZero for equality comparisons.
๐ŸŒ
Zipy
zipy.ai โ€บ blog โ€บ how-do-i-check-if-an-array-includes-a-value-in-javascript
how do i check if an array includes a value in javascript
April 12, 2024 - Arrays are widely used in JavaScript ... them. The includes() method is a built-in array method introduced in ECMAScript 2016 (ES6) that provides a straightforward way to check if an array includes a specific value....
๐ŸŒ
Reddit
reddit.com โ€บ r/typescript โ€บ (silly?) inferencing issue/question for array.includes()
r/typescript on Reddit: (Silly?) inferencing issue/question for Array.includes()
February 9, 2022 -

Usually Typescript is pretty good at looking at mutually exclusive branches and deduce the types of variables when there are multiple options, so I'm embarrassed to even ask this, but here goes nothing.

We have two variables which will serve as an array of stuff, and a value to look for, using the native includes() function for arrays. We will either have an array of strings and search for a string, or an array of integers and search for an integer. We will not have a mixed array of strings and/or integers, and wouldn't like to loosen this definition with Array<string | number> to accommodate incorrect inferencing.

If we just declare the two variables without any branching typescript correctly infers they are of matching types and the function will run just fine, since it's defined as includes(searchElement: T, fromIndex?: number): boolean; for Array<T>

However, once it goes through branching logic, it stops being able to make this inference... here's a naive example of what I'm talking about: Playground link

I must be missing something here!

๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 81-how-to-check-if-array-includes-a-value
How to check if array includes a value in JavaScript? | SamanthaMing.com
@lolinoid: contains > @prvnbist That's a method DOM Nodes, most known example for it would be getting a list of classnames which will be a node list then you can use contain method to see if it has a classname. Or you can convert it to an array and then use includes method