No. There are some cases where obj instanceof Array can be false, even if obj is an Array.

You do have to be careful with instanceof in some edge cases, though, particularly if you're writing a library and so have less control / knowledge of the environment in which it will be running. The issue is that if you're working in a multiple-window environment (frames, iframes), you might receive a Date d (for instance) from another window, in which case d instanceof Date will be false — because d's prototype is the Date.prototype in the other window, not the Date.prototype in the window where your code is running. And in most cases you don't care, you just want to know whether it has all the Date stuff on it so you can use it.

Source: Nifty Snippets

This example, applies to array objects too and so on.

And the standard method suggest by ECMAScript standards to find the class of an Object is to use the toString method from Object.prototype and isArray(variable) uses it internally.

Answer from levi on Stack Overflow
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript instanceof array | example code
JavaScript instanceof Array | Example code
August 8, 2023 - <!DOCTYPE html> <html> <body> <script> const array = [1, 2, 3]; console.log(Array.isArray(array)) </script> </body> </html> ... However, there’s an important point to consider. While using instanceof works well for native JavaScript objects ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › instanceof
instanceof - JavaScript - MDN Web Docs
July 8, 2025 - For instance, you can securely check if a given object is in fact an Array using Array.isArray(), neglecting which realm it comes from. For example, to check if a Node is an SVGElement in a different context, you can use myNode instanceof myNode.ownerDocument.defaultView.SVGElement.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › instanceof-operator-in-javascript
JavaScript Instanceof Operator - GeeksforGeeks
July 11, 2025 - Example 1: Below is the example of the Instanceof Operator. html · <!DOCTYPE html> <html lang="en"> <head> <title> How to Check/Uncheck the checkbox using JavaScript ? </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <h3> Instanceof Operator. </h3> <p id="GFG"></p> <script> let a = ["Geeks", "for", "Geeks"]; document.getElementById("GFG").innerHTML = (a instanceof Array) + "<br>" + (a instanceof Number); </script> </body> </html> Output: JavaScript Instanceof Operator ·
🌐
DEV Community
dev.to › akashkava › difference-between-instanceof-array-and-arrayisarray-4j7f
Difference between instanceOf Array and Array.isArray - DEV Community
October 18, 2021 - For example, var iframe = document.createElement('iframe'); document.body.appendChild(iframe); iArray = window.frames[window.frames.length-1].Array; var arr = new iArray(1,2,3); // [1,2,3] // Correctly checking for Array Array.isArray(arr); ...
🌐
MIT
web.mit.edu › jwalden › www › isArray.html
Determining whether a value is an array
Consider, for example, MochiKit's MochiKit.Base.flattenArray method, whose documentation states that it: Return a new Array consisting of every item in lst with Array items expanded in-place recursively. This differs from flattenArguments in that it only takes one argument and it only flattens items that are instanceof Array. If you happen to be writing JavaScript that crosses window boundaries passing around arrays, you're out of luck trying to use flattenArray.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › isArray
Array.isArray() - JavaScript - MDN Web Docs
Array.isArray() rejects values that aren't actual Array instances, even if they have Array.prototype in their prototype chain — instanceof Array would accept these as it does check the prototype chain.
Top answer
1 of 2
97

1.What is the difference between these two solutions?

isArray is an ES5 method so not supported by older browsers, but it reliably determines if an object is an Array.

instanceof only checks if Array.prototype is on an object's [[Prototype]] chain. It fails when checking arrays across iframes since the Array constructor used for the instance will likely be different to the one used for the test.

2.Which of these two is the preferred solution?

"Preferred" assumes some criterion for selection. Generally, the preferred method is something like:

if (Object.prototype.toString.call(obj) == '[object Array]')

which suits ES3 browsers and works across iframes. If only ES5 browsers are in consideration, isArray is likely OK.

3.Which has a faster process time?

Largely irrelevant, since the processing time for both is negligible. Far more important to select the one that is reliable. An Array.isArray method can be added to browsers that don't have it built–in using:

if (!Array.isArray) {
    Array.isArray = function(obj) {
      return Object.prototype.toString.call(obj) == '[object Array]';
    }
}
2 of 2
50
  1. Difference between Array.isArray(item) and item instanceof Array

    As Felix Kling mentioned in the comment, instanceof Array doesn't work across iframes. To give you a specific example, try the following code:

    var iframeEl = document.createElement('iframe');
    document.body.appendChild(iframeEl);
    iframeArray = window.frames[window.frames.length - 1].Array;
    
    var array1 = new Array(1,1,1,1);
    var array2 = new iframeArray(1,1,1,1);
    
    console.log(array1 instanceof Array);  // true    
    console.log(Array.isArray(array1));  // true
    
    console.log(array2 instanceof Array);  // false    
    console.log(Array.isArray(array2));  // true    
    

    As you see in the example above, array created with the Array constructor in iframe (i.e. array2) is not recognized as an array when you use instanceof Array. However, it is correctly identified as an array when using Array.isArray().

    If you are interested in knowing why instanceof Array doesn't work across different globals (i.e. iframe or window), you can read more about it on here.

  2. Which of these two is the preferred solution?

    In most cases instanceof Array should be enough. However, since instanceof Array doesn't work correctly across iframes/window, Array.isArray() would be more robust solution.

    Make sure to check for browser compatibility though. If you need to support IE 8 or less, Array.isArray() won't work (see Mozilla's doc).

  3. Which has a faster process time?

    According to this jsperf, instanceof Array is faster than Array.isArray(). Which makes sense, because Array.isArray() performs more robust checking and therefore takes a slight performance hit.

🌐
Flexiple
flexiple.com › javascript › instanceof-javascript
JavaScript instanceof operator: Syntax, Example & Explanation - Flexiple
March 11, 2022 - ... var = ["Apple", "Mango", "Banana"]; console.log(fruits instanceof Array); console.log(fruits instanceof Object); console.log(fruits instanceof Number); console.log(fruits instanceof String); //Output true true false false
Find elsewhere
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › classes
Class checking: "instanceof"
September 26, 2025 - ... class Rabbit {} let rabbit = new Rabbit(); // is it an object of Rabbit class? alert( rabbit instanceof Rabbit ); // true ... Please note that arr also belongs to the Object class.
🌐
Esdiscuss
esdiscuss.org › topic › fixing-instanceof-array-isarray-etc
Fixing instanceof (Array.isArray() etc.)?
Array.isArray is OK for Array like objects so that we know that common operation are allowed while instanceof should act exactly as it does now so no confusion cross frame will be possible.
🌐
Perfectionkills
perfectionkills.com › instanceof-considered-harmful-or-how-to-write-a-robust-isarray
instanceof considered harmful or how to write a robust isArray — Perfection Kills
January 10, 2009 - There are usually two schools of ... in array objects). Obviously, both ways have their pros and cons. instanceof operator essentially checks whether anything from left-hand object’s prototype chain is the same object as what’s referenced by prototype property of right-hand object. It sounds somewhat complicated but is easily understood from a simple example...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-check-object-is-an-array-in-javascript
How to Check Object is an Array in JavaScript? - GeeksforGeeks
November 17, 2024 - ... function checkObject() { const countries = ["India", "USA", "Canada"]; const checkArrayObj = Array.isArray(countries); console.log(checkArrayObj); } checkObject(); ... The instanceof operator tests whether an object is an instance of a specific ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-arrays
JavaScript Arrays - GeeksforGeeks
There are two methods by which we can recognize a JavaScript array: By using Array.isArray() method · By using instanceof method · Below is an example showing both approaches: JavaScript · const courses = ["HTML", "CSS", "Javascript"]; ...
Published   October 3, 2025
🌐
W3Schools
w3schools.com › jsref › jsref_oper_instanceof.asp
JavaScript instanceof Operator
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
🌐
DEV Community
dev.to › codecupdev › learn-how-to-use-instanceof-in-javascript-3b0i
Learn how to use instanceof in JavaScript - DEV Community
October 18, 2022 - I will wrap up this article with one last example. const arr = [1, 2, 3] arr instanceof Array //Returns ---> true arr instanceof Object //Returns ---> true
🌐
W3Schools
w3schools.com › js › tryit.asp
JavaScript Operators
The W3Schools online code editor allows you to edit code and view the result in your browser
Top answer
1 of 4
10

Between the constructors, the relationship or prototype chain is:

Array -> Function.prototype -> Object.prototype
Object -> Function.prototype -> Object.prototype

The 1st is true because a constructor is a Function and functions are themselves Objects.

Array instanceof Function // true
Object instanceof Function // true

(function () {}) instanceof Object // true
2 of 4
2

You're testing the Array constructor. The Array constructor is a function used for creating arrays. So Array instanceof Function is true, and Array instanceof Object is true (since all JS objects inherit from the Object prototype. But since this is a constructor function, not an actual array Array instanceof Array is false.

Object is the Object constructor, which all objects inherit from. Since its still a function Object instanceof Function is true, as is Object instanceof Object.

None of that is what you're really meaning (I think) to test. We can test an actual array (rather than the constructor)

and get [] instanceof Array and [] instanceof Object to be true (while [] instanceof Function is false). This is because all arrays are arrays, all arrays are objects, but arrays are not functions.

we can also test an object and get

{} instanceof Object is true, but {} instanceof Array and {} instanceof Function are false.

The key things here

  1. Array is a reference to a constructor function, not an actual array. Constructor functions are Functions, and all Functions are Objects.

  2. An Actual Array is an Array, which means its an Object, but is not a Function.

  3. Under the covers instanceof is looking up an objects "prototype chain" to find any constructors that it inherits from.

🌐
Code with Hugo
codewithhugo.com › detecting-object-vs-array-in-javascript-by-example
JavaScript array type check - “is array” vs object in-depth · Code with Hugo
December 10, 2018 - For those who want some extra spicy ... makes a JavaScript Array an Array you read on or skip to where, we’re going to re-implement isArray. Also known as the “why don’t we just use instanceof Array?” problem. When checking for Array instance, Array.isArray is preferred over instanceof because it works through iframes. See the MDN section/example...
🌐
Dmitri Pavlutin
dmitripavlutin.com › is-array-javascript
3 Ways to Detect an Array in JavaScript - Dmitri Pavlutin
June 29, 2020 - 3 ways to check if a value is an array in JavaScript: Array.isArray(), instanceof Array and toString() === '[object Array]'.