Any object Constructor property return its constructor function, but it doesnt work for Array.
var o={};
o.constructor; --> returns Object()
var a=new Array();
a.constructor; --> Expecting Array() but it returns [undefined]
Any idea?
Any object Constructor property return its constructor function, but it doesnt work for Array.
var o={};
o.constructor; --> returns Object()
var a=new Array();
a.constructor; --> Expecting Array() but it returns [undefined]
Any idea?
The constructor
property of an object will refer to a function. Instead to check if a variable holds an array, do this:
if (Object.prototype.toString.call(a)==='[object Array]') alert('Array!');
The proposed a.length workaround will not work 100 % because it's possible to have an object that has the length property without being an actual array.