ECMAScript 2016 incorporates an includes() method for arrays that specifically solves the problem, and so is now the preferred method.

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false
[1, 2, 3].includes(1, 2);  // false (second parameter is the index position in this array at which to begin searching)

As of JULY 2018, this has been implemented in almost all major browsers, if you need to support an older browser a polyfill is available.

Edit: Note that this returns false if the item in the array is an object. This is because similar objects are two different objects in JavaScript.

Answer from Alister on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_includes_array.asp
JavaScript Array includes() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
People also ask

Can includes() check for objects in an array?
Not effectively. includes() uses strict equality (===), which checks reference identity for objects. Two objects with the same properties are not considered equal unless they are the exact same reference. For object searches, use Array.find() or Array.some() with a callback that compares the properties you need.
๐ŸŒ
savvy.co.il
savvy.co.il โ€บ blog โ€บ javascript complete guide โ€บ check if a value exists in an array using js or jquery
Check if a Value exists in an Array using JS or jQuery | Savvy
How do I check if an object exists in an array?
Use Array.find() to get the matching object, or Array.some() to get a boolean result. For example: users.find(u => u.name === 'Bob') returns the object if found, or undefined if not. These methods accept a callback function, so you can match by any property.
๐ŸŒ
savvy.co.il
savvy.co.il โ€บ blog โ€บ javascript complete guide โ€บ check if a value exists in an array using js or jquery
Check if a Value exists in an Array using JS or jQuery | Savvy
What is the fastest way to check if a value exists in a large array?
For large arrays where you perform frequent lookups, consider converting the array to a Set first: const mySet = new Set(myArray). Then use mySet.has(value) for O(1) lookups instead of O(n). For one-time checks on smaller arrays, includes() is perfectly fast and readable.
๐ŸŒ
savvy.co.il
savvy.co.il โ€บ blog โ€บ javascript complete guide โ€บ check if a value exists in an array using js or jquery
Check if a Value exists in an Array using JS or jQuery | Savvy
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array
Array - JavaScript | MDN
1 week ago - Array elements are object properties in the same way that toString is a property (to be specific, however, toString() is a method). Nevertheless, trying to access an element of an array as follows throws a syntax error because the property name is not valid: ... JavaScript syntax requires properties beginning with a digit to be accessed using bracket notation instead of dot notation.
๐ŸŒ
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:
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ some
Array.prototype.some() - JavaScript | MDN
1 week ago - The some() method of Array instances returns true if it finds an element in the array that satisfies the provided testing function. Otherwise, it returns false.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ every
Array.prototype.every() - JavaScript | MDN
1 week ago - The array argument is useful if you want to access another element in the array. The following example first uses filter() to extract the positive values and then uses every() to check whether the array is strictly increasing.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_array_search.asp
JavaScript Array Search
The findIndex() method returns the index of the first array element that passes a test function. This example finds the index of the first element that is larger than 18:
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ javascript-array-contains
JavaScript Array Contains: 6 Methods to Find a Value | Built In
Learn how to discover what a JavaScript ... multiple methods to check if an array contains a value, including indexOf, includes, some, find and findIndex....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ check-if-an-element-is-present-in-an-array-using-javascript
Check if an element is present in an array using JavaScript - GeeksforGeeks
July 23, 2025 - Checking if an element is present in an array using JavaScript involves iterating through the array and comparing each element with the target value.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-check-if-a-variable-is-an-array-in-javascript
How to Check if a Variable is an Array in JavaScript? - GeeksforGeeks
July 11, 2025 - The Array.isArray() method checks if a variable is an array. It returns true if the variable is an array and false otherwise. This method is introduced in ECMAScript 5. ... // Given variables let n = 10; console.log("Is Array: ", Array.isArray(n)); ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-check-if-an-array-includes-an-object-in-javascript
How to check if an array includes an object in JavaScript ? - GeeksforGeeks
Check if an array includes an object in JavaScript, which refers to determining whether a specific object is present within an array.
Published ย  July 11, 2025
๐ŸŒ
Futurestud.io
futurestud.io โ€บ tutorials โ€บ check-if-a-value-is-an-array-in-javascript-or-node-js
Check If a Value Is an Array in JavaScript or Node.js
December 15, 2022 - This may be a required check in your code when allowing single items or an array of items as a method argument. This tutorial walks you through the pitfalls of using typeof and shows you how to properly detect whether a value is an array! ... You may have used the typeof operator generally in JavaScript.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_isarray.asp
JavaScript Array isArray() Method
Array.isArray() is a static property of the JavaScript Array object. You can only use it as Array.isArray(). Using x.isArray(), where x is an array will return undefined. ... If you want to use W3Schools services as an educational institution, ...
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ javascript โ€บ standard-library โ€บ Array โ€บ isArray
JavaScript Array isArray() - Check If Array | Vultr Docs
November 28, 2024 - The Array.isArray() function is a dependable method to ascertain if a value is an actual array or not in JavaScript. This method is crucial for maintaining the integrity of operations and functionalities that specifically deal with array ...
Top answer
1 of 16
2066

There are several ways of checking if an variable is an array or not. The best solution is the one you have chosen.

variable.constructor === Array

This is the fastest method on Chrome, and most likely all other browsers. All arrays are objects, so checking the constructor property is a fast process for JavaScript engines.

If you are having issues with finding out if an objects property is an array, you must first check if the property is there.

variable.prop && variable.prop.constructor === Array

Some other ways are:

Array.isArray(variable)

Update May 23, 2019 using Chrome 75, shout out to @AnduAndrici for having me revisit this with his question This last one is, in my opinion the ugliest, and it is one of the slowest fastest. Running about 1/5 the speed as the first example. This guy is about 2-5% slower, but it's pretty hard to tell. Solid to use! Quite impressed by the outcome. Array.prototype, is actually an array. you can read more about it here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray

variable instanceof Array

This method runs about 1/3 the speed as the first example. Still pretty solid, looks cleaner, if you're all about pretty code and not so much on performance. Note that checking for numbers does not work as variable instanceof Number always returns false. Update: instanceof now goes 2/3 the speed!

So yet another update

Object.prototype.toString.call(variable) === '[object Array]';

This guy is the slowest for trying to check for an Array. However, this is a one stop shop for any type you're looking for. However, since you're looking for an array, just use the fastest method above.

Also, I ran some test: http://jsperf.com/instanceof-array-vs-array-isarray/35 So have some fun and check it out.

Note: @EscapeNetscape has created another test as jsperf.com is down. http://jsben.ch/#/QgYAV I wanted to make sure the original link stay for whenever jsperf comes back online.

2 of 16
1196

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ javascript โ€บ examples โ€บ check-if-an-array-contains-a-specified-value
JavaScript Program to Check if An Array Contains a Specified Value | Vultr Docs
September 27, 2024 - Start with the simplest and most direct method using includes() to check for a value. Create an array and use includes() to determine if a specified value is present.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ find
Array.prototype.find() - JavaScript | MDN
A function to execute for each element in the array. It should return a truthy value to indicate a matching element has been found, and a falsy value otherwise.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ check-if-an-item-is-in-an-array-in-javascript-js-contains-with-array-includes
Check if an Item is in an Array in JavaScript โ€“ JS Contains with Array.includes()
June 28, 2022 - You can use the includes() method in JavaScript to check if an item exists in an array. You can also use it to check if a substring exists within a string. It returns true if the item is found in the array/string and false if the item doesn't ...