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 a shorter option
Source Link
Gust van de Wal
  • 5.3k
  • 1
  • 27
  • 52

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject (n) {
  return Object.prototype.toString.call(n) === '[object Object]';
}

Or as a single-expression arrow function (ES6+)

const isObject = n => Object.prototype.toString.call(n) === '[object Object]'

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject(n) {
  return Object.prototype.toString.call(n) === '[object Object]';
}

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject (n) {
  return Object.prototype.toString.call(n) === '[object Object]';
}

Or as a single-expression arrow function (ES6+)

const isObject = n => Object.prototype.toString.call(n) === '[object Object]'
deleted 36 characters in body
Source Link
sasi
  • 322
  • 2
  • 9

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject(n) {
  if (n == null) return false;
  return Object.prototype.toString.call(n) === '[object Object]';
}

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject(n) {
  if (n == null) return false;
  return Object.prototype.toString.call(n) === '[object Object]';
}

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject(n) {
  return Object.prototype.toString.call(n) === '[object Object]';
}
Fixed unnecessary explicit return value.
Source Link
sasi
  • 322
  • 2
  • 9

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject(n) {
  if (n == null) return false;
  ifreturn (Object.prototype.toString.call(n) === '[object Object]') return true;
  return false;Object]';
}

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject(n) {
  if (n == null) return false;
  if (Object.prototype.toString.call(n) === '[object Object]') return true;
  return false;
}

If you would like to check if the prototype for an object solely comes from Object. Filters out String, Number, Array, Arguments, etc.

function isObject(n) {
  if (n == null) return false;
  return Object.prototype.toString.call(n) === '[object Object]';
}
Source Link
sasi
  • 322
  • 2
  • 9
Loading