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
🌐
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.
🌐
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.
🌐
DEV Community
dev.to › akashkava › difference-between-instanceof-array-and-arrayisarray-4j7f
Difference between instanceOf Array and Array.isArray - DEV Community
October 18, 2021 - With Object.create, Array.prototype is present in prototype chain of a, so instanceOf Array will be true, as in the context of JavaScript, a has prototype of Array.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › instanceof-operator-in-javascript
JavaScript Instanceof Operator - GeeksforGeeks
July 11, 2025 - <!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 fruits = ["Apple", "Mango", "Banana"]; document.getElementById("GFG").innerHTML = (fruits instanceof Array) + "<br>" + (fruits instanceof Object) + "<br>" + (fruits instanceof String) + "<br>" + (fruits instanceof Number); </script> </body> </html> Output: JavaScript Instanceof Operator ·
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › classes
Class checking: "instanceof"
September 26, 2025 - That’s because Array prototypically inherits from Object. Normally, instanceof examines the prototype chain for the check. We can also set a custom logic in the static method Symbol.hasInstance. The algorithm of obj instanceof Class works roughly as follows: If there’s a static method Symbol.hasInstance, then just call it: Class[Symbol.hasInstance](obj).
🌐
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. Note: Array.isArray() in general returns false for array-like objects:
🌐
CoreUI
coreui.io › blog › what-is-the-difference-between-typeof-and-instanceof-in-javascript
What is the difference between typeof and instanceof in JavaScript · CoreUI
September 17, 2024 - Note: Both arrays and objects return 'object' when using typeof. To differentiate between them, you might need additional checks. The instanceof operator checks if an object is an instance of a specific class or constructor function.
🌐
MIT
web.mit.edu › jwalden › www › isArray.html
Determining whether a value is an array
The shared-mutation hazard of having arrays in two coordinating windows be instances of the same Array constructor, sharing the same Array.prototype, is enormous when either page augments Array.prototype (not to mention the security problems when one page is malicious!), so Array and Array.prototype in each window must be different. Therefore, by the semantics of instanceof, o instanceof Array works correctly only if o is an array created by that page's original Array constructor (or, equivalently, by use of an array literal in that page).
Find elsewhere
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › type › array typechecking
Typechecking JavaScript arrays with Array.isArray() - 30 seconds of code
November 6, 2022 - let iframeEl = document.createElement('iframe'); document.body.appendChild(iframeEl); iframeArray = window.frames[window.frames.length - 1].Array; let array1 = new Array(1,1,1,1); let 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
🌐
Dmitri Pavlutin
dmitripavlutin.com › is-array-javascript
3 Ways to Detect an Array in JavaScript - Dmitri Pavlutin
June 29, 2020 - Now emerges the next way to detect an array: value instanceof Array evaluates to true if value is an array.
🌐
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.

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.

🌐
W3Schools
w3schools.com › jsref › jsref_isarray.asp
JavaScript Array isArray() Method
: ?. ... () ? x : y => delete in instanceof typeof void JS Precedence JS Promises
🌐
Flexiple
flexiple.com › javascript › instanceof-javascript
JavaScript instanceof operator: Syntax, Example & Explanation - Flexiple
March 11, 2022 - The JavaScript instanceof operator is used to check the type of an object at the run time. It returns a boolean value(true or false). If the returned value is true, then it indicates that the object is an instance of a particular class and if ...
🌐
SamanthaMing
samanthaming.com › tidbits › 63-better-array-check-with-array-isarray
Better Array check with Array.isArray | SamanthaMing.com
And when you get a bit more comfortable with JavaScript, then definitely return to this topic. In the meantime, let me try to explain this "multiple context" in non-dev terms. You can think of frames like different planets. Every planet has its own system, with different gravity pull and composition. So instanceof only works on our planet, Earth. If you bring it to Mars, it won't work. However, with Array.isArray() it will work on any planet.
🌐
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 - Is Array: false Is Array: false Is Array: true · The JavaScript instanceof operator is used to test whether the prototype property of a constructor appears anywhere in the prototype chain of an object.
🌐
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 - Checking for arrays, on the other hand, is a somewhat tricky business. There are usually two schools of thought – using instanceof operator (or checking object’s constructor property) and the-duck-typing way – checking for presence (or types) of certain set of properties (which are known to be present in array objects).
🌐
W3Schools
w3schools.com › jsref › jsref_oper_instanceof.asp
JavaScript instanceof Operator
const cars = ["Saab", "Volvo", "BMW"]; (cars instanceof Array) // Returns true (cars instanceof Object) // Returns true (cars instanceof String) // Returns false (cars instanceof Number) // Returns false Try it Yourself » · The typeof operator · instanceof is an ECMAScript3 (JavaScript 1999) feature.