function isObject(val) {
  return val != null && typeof val === 'object' && Array.isArray(val) === false;
};


True

All of the following return true:

isObject({});
isObject(Object.create({}));
isObject(Object.create(Object.prototype));
isObject(Object.create(null));
isObject({});
isObject(new Foo);
isObject(/foo/);
False

All of the following return false:

isObject();
isObject(function () {});
isObject(1);
isObject([]);
isObject(undefined);
isObject(null);
if (!Array.isArray) {
  Array.isArray = function(arg) {
    return Object.prototype.toString.call(arg) === '[object Array]';
  };
}

var arr = new xArray(1,2,3); // [1,2,3]
Array.isArray(arr);  // true

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-23
  • 2021-10-31
  • 2022-12-23
  • 2021-09-08
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案