Javascript Array isArray: How to Use Javascript.isArray()

Javascript Array isArray Tutorial With Example | Array.isArray() Function

To check if the input value is an array or not then we can use the Javascript isArray() function.

There are some use cases like let say, we are fetching the json data from the server, and then we convert it into an object, and then if we wanted to make sure that the data object contains the array values or not then we can use the isArray() function.

We can check the data type of any value of Javascript using the typeof operator.

Javascript Array isArray

Javascript array isArray() is an inbuilt function that determines whether the passed value is an array or not. If the value is an array, then true is returned; otherwise, false is return. When checking for the Array instance, the isArray() function is preferred over the instanceof because it works through iframes.


See the syntax of Javascript isArray() function.



The value to be checked.


See the following example.

// app.js

let arr = ['Millie', 'Bobby', 'Brown'];

let data = {
  realname: 'Millie Bobby Brown',
  character: 'Eleven',
  series: 'Stranger Things'

In the above example, we have defined an array of Strings and an array of Objects.

See the following output.

➜  es git:(master) ✗ node app
➜  es git:(master) ✗

#Javascript isArray behavior with different types

Empty Array [] true
An array of Number literal [1,2,3] true
An array of String literal [“a” “b”, “c”] true
Array (using constructor.from) [null,null,null,null,null,null,null,null,null,null] true
Array with empty values using constructor [null,null,null,null,null,null,null,null,null,null] true
Array with values using constructor [1,2,3] true
Array prototype [] true
Array from another window [1,2,3] true
Empty Object {} false
Object with .length property {“length”:10} false
Object whose __prototype__ is Array {} false
Object {“a”: “2”, “b”: “c”} false
Object with nested Array {“nested”:[“2”, “c”]} false
Empty Set {} false
Set of String {} false
Set of Number {} false
Empty Map {} false
Map with different types {} false
String literal “hello world.” false
String Object “hello world” false
Boolean true literal true false
Boolean false literal false false
Explicitly undefined undefined false
Implicit undefined undefined false
null null false
Number (integer) 123 false
Number (float) 1.23 false

An array can be checked if it is empty by using the array.length property. This property returns several elements in the array.

If the number is greater than 0, it evaluates to true.

This method and property can be both used together with the AND(&&) operator to determine whether the array exists and is not empty.

Array isArray() Polyfill

Running the following code before any other code will create Array.isArray() if it’s not natively available in your browser.

if (!Array.isArray) {
  Array.isArray = function(arg) {
    return === '[object Array]';

Finally, Javascript Array isArray() Function example is over.

See also

Javascript array to json

Javascript array toString

Javascript array reverse()

1 Comment

Leave A Reply

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.