Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 208 characters in body
Source Link
cn0047
  • 17.2k
  • 7
  • 61
  • 75

With function Array.isArray:

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

Without function Array.isArray:

There is already created package on npm v1 based on this implementation! And it works for all earlier described test cases! ๐Ÿ™‚

There is already created package on npm based on this implementation! And it works for all earlier described test cases! ๐Ÿ™‚

With function Array.isArray:

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

Without function Array.isArray:

There is already created package on npm v1 based on this implementation! And it works for all earlier described test cases! ๐Ÿ™‚

deleted 52 characters in body
Source Link
cn0047
  • 17.2k
  • 7
  • 61
  • 75

isObject won't work in case of Object.create(null) because of internal implementation of Object.create which is explained herehere but you can use isObject in more sophisticated implementation:

isObject won't work in case of Object.create(null) because of internal implementation of Object.create which is explained here but you can use isObject in more sophisticated implementation:

isObject won't work in case of Object.create(null) because of internal implementation of Object.create which is explained here but you can use isObject in more sophisticated implementation:

added 1161 characters in body
Source Link
cn0047
  • 17.2k
  • 7
  • 61
  • 75

isObject won't work in case of Object.create(null) because of internal implementation of Object.create which is explained here but you can use isObject in more sophisticated implementation:

function isObject(o, strict = true) {
  if (o === null || o === undefined) {
    return false;
  }
  const instanceOfObject = o instanceof Object;
  const typeOfObject = typeof o === 'object';
  const constructorUndefined = o.constructor === undefined;
  const constructorObject = o.constructor === Object;
  const typeOfConstructorObject = typeof o.constructor === 'function';
  let r;
  if (strict === true) {
    r = (instanceOfObject || typeOfObject) && (constructorUndefined || constructorObject);
  } else {
    r = (constructorUndefined || typeOfConstructorObject);
  }
  return r;
};

There is already created package on npm based on this implementation! And it works for all earlier described test cases! ๐Ÿ™‚


isObject won't work in case of Object.create(null) because of internal implementation of Object.create which is explained here but you can use isObject in more sophisticated implementation:

function isObject(o, strict = true) {
  if (o === null || o === undefined) {
    return false;
  }
  const instanceOfObject = o instanceof Object;
  const typeOfObject = typeof o === 'object';
  const constructorUndefined = o.constructor === undefined;
  const constructorObject = o.constructor === Object;
  const typeOfConstructorObject = typeof o.constructor === 'function';
  let r;
  if (strict === true) {
    r = (instanceOfObject || typeOfObject) && (constructorUndefined || constructorObject);
  } else {
    r = (constructorUndefined || typeOfConstructorObject);
  }
  return r;
};

There is already created package on npm based on this implementation! And it works for all earlier described test cases! ๐Ÿ™‚

added 392 characters in body
Source Link
cn0047
  • 17.2k
  • 7
  • 61
  • 75
Loading
added 108 characters in body
Source Link
cn0047
  • 17.2k
  • 7
  • 61
  • 75
Loading
added 52 characters in body
Source Link
cn0047
  • 17.2k
  • 7
  • 61
  • 75
Loading
added 382 characters in body
Source Link
cn0047
  • 17.2k
  • 7
  • 61
  • 75
Loading
Source Link
cn0047
  • 17.2k
  • 7
  • 61
  • 75
Loading