Check if your variable is an Array in Javascript.

Learn Different ways to check if a variable is array in Javascript.

Using Array.isArray()


Using toString() method in Object, this method convert the argument to specific type name,

If we pass Object.prototype.toString.call(1) returns "[object Number]"Β , so if we pass array then it results in "[object Array]"Β .


Using instanceof keyword

arr instanceof Array;

Using toString method on the variable

Let’s assume we have a variable a = 10Β , when we call a.constructor.toString() it returns "function Number() { [native code] }” . Similarly if we pass array then instead of number it returns Array.



Learn about unknown things about ** operator here.

If you find this helpful surprise 🎁 me here.

Share if you feel happy πŸ˜ƒ πŸ˜† πŸ™‚Β .

Follow Javascript JeepπŸš™ if you feel worthy.

Leave a comment

Design a site like this with WordPress.com
Get started