Interview Q&A / JavaScript

BeginnerQuick answer1 min readUpdated 3 Oct 2026

How do you check whether a value is an array in JavaScript?

SHORT ANSWER

Use Array.isArray(value). typeof returns "object" for arrays, and instanceof Array can fail for arrays created in another frame or realm.

Explain it simply

Arrays are a special kind of object, so typeof cannot tell them apart from a plain object: both say "object". You need a check that knows about arrays specifically.

Options:

  1. Array.isArray(value): the right answer. Built for exactly this job, and works everywhere.
  2. value instanceof Array: works in most cases, but fails when the array came from a different window, such as an iframe, because each window has its own Array constructor.
  3. Object.prototype.toString.call(value) === "[object Array]": an older trick from before ES5.

Example

js
const marks = [78, 91, 66];
const student = { name: "Neha", marks: 3 };
const arrayLike = { 0: "a", 1: "b", length: 2 };

console.log(typeof marks);                 // Output: object
console.log(Array.isArray(marks));         // Output: true
console.log(Array.isArray(student));       // Output: false
console.log(Array.isArray(arrayLike));     // Output: false
console.log(Object.prototype.toString.call(marks)); // Output: [object Array]
console.log(Array.isArray(Array.from(arrayLike)));  // Output: true

An object with a length property is "array-like" but not an array. Array.from turns it into a real one.

What to say in the interview

"I use Array.isArray. typeof gives 'object' for arrays, and instanceof Array breaks across realms like iframes because each has its own Array constructor. Array.isArray checks the internal type, so it's reliable. Before ES5, people used Object.prototype.toString.call(value)."

Common mistakes

  • Checking value.length to decide it is an array; strings and array-like objects have length too.

#javascript#arrays#types

Related questions

Practise more JavaScript questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open JavaScript quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.