判断数组和对象

89 阅读1分钟

1.判断是否是对象的方法:

   1. Object.prototype.toString.call(val) === '[Object Object]'
   2. val.constructor === Object  判断构造函数
   3. val.__proto === Object.prototype;
   4. Object.getPrototyOf(val) === Object.prototype;
  1. 判断是否是数组的方法
   1. Object.prototype.toString.call(val) === '[Object Array]
   2. Array.isArray(val)
   3. val instanceof Array
   4. var?.constructor === Array 
   5. val.__proto__ === Array.prototype;
   6. Object.getPrototyOf(val) === Array.prototype;
   7. Array.prototype.isPrototyOf(val)