Christian Giacomi

An attempt at a small developer blog

Check if a value is an array in JavaScript

Posted at — Sep 6, 2017   Category — software 

I am sure it has happened to everyone to call a function in Javascript without knowing exactly the return type. The question is, how can I test that value to see if it’s an array?

This is especially true if you have business logic that differentiates between an array and a normal value, and performs different instructions based on the type.

Well it’s actually super easy to do that. Always use the isArray() static method provided by the runtime on the Array object, introduced in ECMAScript: 5

Here is the way you would check.

const list = ['a', 'b', 'c', 'd']
Array.isArray(list) //true
If this post was helpful tweet it or share it.