Check variable is Array using jQuery

Today for one of my functionality, I need to check whether the Java script variable is an array or not. jQuery provides a method "jQuery.isArray()" to check whether the element is Java script array or not.

jQuery.isArray() returns a boolean value that indicates whether the object is a JavaScript array or not. It takes the variable name as an argument and returns the result back to caller. See below jQuery code.

   var x = [];
   var y = [1,2,3];
   var z = 1;
   alert('x is an array: ' + $.isArray(x));
   alert('y is an array: ' + $.isArray(y));
   alert('z is an array: ' + $.isArray(z));
In the above jQuery code, I have declared 3 variables x,y and z. And out of 3, x and y variables are array where z is not. When you run this then you will see that for variable x and y it returns true and for z it returns false.

Check this article to find find index of element in array using jQuery.

See live Demo and Code.

Feel free to contact me for any help related to jQuery. I will gladly help you.

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..