Object or Array
Tagged with: array, JavaScript, object, type
Find whether the given variable is an object,or is an Array?
function isArray(testObject) {
return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}
Original Page
[tags]javascript,object,array,type[/tags]
Follow me(@binnyva) on Twitter
July 29th, 2010 09:02
Why not just use
function test(Object){
return object.constructor.name===”Array”
}
?