top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to check if a variable is array in JavaScript?

+2 votes
How to check if a variable is array in JavaScript?
posted Mar 28, 2014 by Madhavi Latha

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+1 vote

Simplest way is

if (value instanceof Array) {
} else {
 alert('Not an array');

Another way is use of angular.isArray() function.

answer Mar 28, 2014 by Salil Agrawal
0 votes

Fastest method

variable.constructor === Array

2nd method (check the property)

variable.prop && variable.prop.constructor === Array

3rd method (easy one)

variable instanceof Array

Slowest method

answer Dec 21, 2016 by Atindra Kumar Nath
Similar Questions
0 votes

I have a variable created by some rails in my controller that looks like this:

@myvar= row["myvar"]

and I want to pass it into some javascript that is referenced from within my view:


js (play_time):

I am trying to pass " into the js [obviously that is not the right syntax]. Can anyone help?

+2 votes

Is there any way so that i will get to know about my variable is a number or not without using Javascript?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.