No, it doesn't have one. For this reason most popular libraries come with one in their utility packages. Check out jQuery's inArray and Prototype's Array.indexOf for examples.

jQuery's implementation of it is as simple as you might expect:

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

If you are dealing with a sane amount of array elements the above will do the trick nicely.

EDIT: Whoops. I didn't even notice you wanted to see if an array was inside another. According to the PHP documentation this is the expected behavior of PHP's in_array:

$a = array(array('p', 'h'), array('p', 'r'), 'o');

if (in_array(array('p', 'h'), $a)) {
    echo "'ph' was found\n";
}

if (in_array(array('f', 'i'), $a)) {
    echo "'fi' was found\n";
}

if (in_array('o', $a)) {
    echo "'o' was found\n";
}

// Output:
//  'ph' was found
//  'o' was found

The code posted by Chris and Alex does not follow this behavior. Alex's is the official version of Prototype's indexOf, and Chris's is more like PHP's array_intersect. This does what you want:

function arrayCompare(a1, a2) {
    if (a1.length != a2.length) return false;
    var length = a2.length;
    for (var i = 0; i < length; i++) {
        if (a1[i] !== a2[i]) return false;
    }
    return true;
}

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(typeof haystack[i] == 'object') {
            if(arrayCompare(haystack[i], needle)) return true;
        } else {
            if(haystack[i] == needle) return true;
        }
    }
    return false;
}

And this my test of the above on it:

var a = [['p','h'],['p','r'],'o'];
if(inArray(['p','h'], a)) {
    alert('ph was found');
}
if(inArray(['f','i'], a)) {
    alert('fi was found');
}
if(inArray('o', a)) {
    alert('o was found');
}  
// Results:
//   alerts 'ph' was found
//   alerts 'o' was found

Note that I intentionally did not extend the Array prototype as it is generally a bad idea to do so.

Answer from Paolo Bergantino on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
The includes() method compares searchElement to elements of the array using the SameValueZero algorithm. Values of zero are all considered to be equal, regardless of sign. (That is, -0 is equal to 0), but false is not considered to be the same as 0.
🌐
BrainStation®
brainstation.io › learn › javascript › array
JavaScript Array (2025 Tutorial & Examples) | BrainStation®
February 4, 2025 - Array In JavaScript, arrays aren’t primitive values. They are instead Array objects that provide the ability to store an indexed collection of values as a list. JavaScript arrays are resizable and can contain a mix of different data types.
🌐
Medium
medium.com › @vetriselvan_11 › understanding-array-includes-in-javascript-what-happens-under-the-hood-bd90daa246cb
Understanding Array.includes() in JavaScript — What Happens Under the Hood? | by Vetriselvan Panneerselvam | Medium
June 30, 2025 - const nameList = ['ram', 'joyal', 'ayoob', 'abdul', 'vasanth', 'alan']; console.log(nameList.includes('ayoob', 10)); // Output: false ... If fromIndex > nameList.length, the method short-circuits and returns false immediately. The array isn't even searched.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › with
Array.prototype.with() - JavaScript | MDN
July 10, 2025 - The with() method creates and returns a new array. It reads the length property of this and then accesses each property whose key is a nonnegative integer less than length. As each property of this is accessed, the array element having an index equal to the key of the property is set to the value of the property.
🌐
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 TOOLS ... 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
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-methods
JavaScript Array Methods - GeeksforGeeks
To help you perform common tasks efficiently, JavaScript provides a wide variety of array methods. These methods allow you to add, remove, find, and transform array elements with ease. ... The length property of an array returns the number of elements in the array.
Published   August 5, 2025
Top answer
1 of 16
282

No, it doesn't have one. For this reason most popular libraries come with one in their utility packages. Check out jQuery's inArray and Prototype's Array.indexOf for examples.

jQuery's implementation of it is as simple as you might expect:

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

If you are dealing with a sane amount of array elements the above will do the trick nicely.

EDIT: Whoops. I didn't even notice you wanted to see if an array was inside another. According to the PHP documentation this is the expected behavior of PHP's in_array:

$a = array(array('p', 'h'), array('p', 'r'), 'o');

if (in_array(array('p', 'h'), $a)) {
    echo "'ph' was found\n";
}

if (in_array(array('f', 'i'), $a)) {
    echo "'fi' was found\n";
}

if (in_array('o', $a)) {
    echo "'o' was found\n";
}

// Output:
//  'ph' was found
//  'o' was found

The code posted by Chris and Alex does not follow this behavior. Alex's is the official version of Prototype's indexOf, and Chris's is more like PHP's array_intersect. This does what you want:

function arrayCompare(a1, a2) {
    if (a1.length != a2.length) return false;
    var length = a2.length;
    for (var i = 0; i < length; i++) {
        if (a1[i] !== a2[i]) return false;
    }
    return true;
}

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(typeof haystack[i] == 'object') {
            if(arrayCompare(haystack[i], needle)) return true;
        } else {
            if(haystack[i] == needle) return true;
        }
    }
    return false;
}

And this my test of the above on it:

var a = [['p','h'],['p','r'],'o'];
if(inArray(['p','h'], a)) {
    alert('ph was found');
}
if(inArray(['f','i'], a)) {
    alert('fi was found');
}
if(inArray('o', a)) {
    alert('o was found');
}  
// Results:
//   alerts 'ph' was found
//   alerts 'o' was found

Note that I intentionally did not extend the Array prototype as it is generally a bad idea to do so.

2 of 16
189

There is now Array.prototype.includes:

The includes() method determines whether an array includes a certain element, returning true or false as appropriate.

var a = [1, 2, 3];
a.includes(2); // true 
a.includes(4); // false

Syntax

arr.includes(searchElement)
arr.includes(searchElement, fromIndex)
Find elsewhere
🌐
Medium
medium.com › @mandeepkaur1 › a-list-of-javascript-array-methods-145d09dd19a0
A List of JavaScript Array Methods | by Mandeep Kaur | Medium
February 28, 2020 - In JavaScript, an array is a data structure that contains list of elements which store multiple values in a single variable. The strength of JavaScript arrays lies in the array methods.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › includes
JavaScript Array includes() - Determine Presence in Array | Vultr Docs
November 28, 2024 - In this article, you will learn how to effectively use the includes() method in various scenarios. Explore how to implement this method to enhance code readability and efficiency, from checking simple presence to applying it in conditions with logical operators. Define an array with several elements.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Typed_arrays
JavaScript typed arrays - JavaScript | MDN
JavaScript typed arrays are array-like objects that provide a mechanism for reading and writing raw binary data in memory buffers.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
February 24, 2026 - The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name, and has members for performing common array operations. In JavaScript, arrays aren't primitives but are instead Array objects with the following core ...
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Array methods
The arr.splice method is a Swiss army knife for arrays. It can do everything: insert, remove and replace elements.
🌐
Quora
quora.com › What-are-arrays-in-JavaScript
What are arrays in JavaScript? - Quora
Answer (1 of 2): an array in JavaScript and many other languages is a data structure that allows us to store multiple values tied to one variable, like a list [code]let myArray = [1, 2, 3, 5]; [/code]the values in the brackets (which can be ...
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-array
JavaScript Arrays: Create, Access, Add & Remove Elements
JavaScript array is a special type of variable, which can store multiple values using a special syntax. Learn what is an array and how to create, add, remove elements from an array in JavaScript.
🌐
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 - It returns true if the item is found in the array/string and false if the item doesn't exist. In this article, you'll see how to use the includes() method in JavaScript to check if an item is in an Array, and if a substring exists within a string.
🌐
Scaler
scaler.com › home › topics › javascript array includes() method
JavaScript Array includes() Method - Scaler Topics
February 14, 2024 - The Array includes() method in JavaScript is a built-in function used to search for a specific element within an array. Whether it's a number, string, or any other character, includes() performs a case-sensitive search to determine the presence of the specified value in the array.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.includes()
JavaScript Array includes() Method
November 7, 2024 - const cars = [ford, toyota];Code language: JavaScript (javascript) Third, check if the cars array contains the ford object using the includes() method and display the result to the console: