check variable is a array or object

function isArray(o) {
  return === ‘[object Array]’;


The Miller Device
The JavaScript language currently does not provide a good way to distinguish between objects and arrays. The typeof operator is broken: It identifies arrays as objects. Comparing a value’s constructor property doesn’t work because arrays created in a different frame will have a different constructor. There are do-it-yourself tests for arrayness, but they are complicated and unreliable.
Mark Miller of The Google, by closely reading the ECMAScript standard, has discovered a simpler, more reliable test.
Object.prototype.toString.apply(value) === ‘[object Array]’



Fill in your details below or click an icon to log in: 徽标

You are commenting using your account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )


Connecting to %s