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 14 characters in body
Source Link
Alireza
  • 105.5k
  • 27
  • 280
  • 173

OK, let's give you this concept first before answering your question, in JavaScript Functions are Object, also null, Object, Arrays and even Date, so as you see it's notthere is not a simple way like typeof obj === 'object', so everything mentioned above will return truereturn true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it gets checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these functions as above in your code by calling them and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript framework, they usually have prepared these kind of functions for you, these are few of them:

jQuery:

 //It returns 'object' if real Object;
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);

OK, let's give you this concept first before answering your question, in JavaScript Functions are Object, also null, Object, Arrays and even Date, so as you see it's not simple way like typeof obj === 'object', so everything mentioned above will return true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it gets checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these functions as above in your code by calling them and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript framework, they usually have prepared these kind of functions for you, these are few of them:

jQuery:

 //It returns 'object' if real Object;
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);

OK, let's give you this concept first before answering your question, in JavaScript Functions are Object, also null, Object, Arrays and even Date, so as you see there is not a simple way like typeof obj === 'object', so everything mentioned above will return true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it gets checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these functions as above in your code by calling them and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript framework, they usually have prepared these kind of functions for you, these are few of them:

jQuery:

 //It returns 'object' if real Object;
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);
edited body
Source Link
Alireza
  • 105.5k
  • 27
  • 280
  • 173

OK, let's give you this concept first before answering your question, in JavaScript Functions are objectObject, also null, Object, Arrays and even Date, so as you see it's not simple way like typeof obj === 'object', so everything mentioned above will return true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it gets checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these functions as above in your code by calling them and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript framework, they usually have prepared these kind of functions for you, these are few of them:

jQuery:

 //It returns 'object' if real Object;
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);

OK, let's give you this concept first before answering your question, in JavaScript Functions are object, also null, Object, Arrays and even Date, so as you see it's not simple way like typeof obj === 'object', so everything mentioned above will return true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it gets checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these functions as above in your code by calling them and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript framework, they usually have prepared these kind of functions for you, these are few of them:

jQuery:

 //It returns 'object' if real Object;
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);

OK, let's give you this concept first before answering your question, in JavaScript Functions are Object, also null, Object, Arrays and even Date, so as you see it's not simple way like typeof obj === 'object', so everything mentioned above will return true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it gets checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these functions as above in your code by calling them and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript framework, they usually have prepared these kind of functions for you, these are few of them:

jQuery:

 //It returns 'object' if real Object;
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);
added 17 characters in body
Source Link
Alireza
  • 105.5k
  • 27
  • 280
  • 173

OK, let's give you this concept first before answering your question, in JavaScript Functions are object, also null, Object, Arrays and even Date, so as you see it's not simple way like typeof obj === 'object', so everything mentioned above will return true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it'sit getgets checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these above functions as above in your code by calling them like this and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript frameworksframework, they usually have prepared the functionthese kind of functions for you, these are few of them:

jQuery:

 //It returns 'object';'object' if real Object;
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);

OK, let's give you this concept first before answering your question, in JavaScript Functions are object, also null, Object, Arrays and even Date, so as you see it's not simple way like typeof obj === 'object', so everything mentioned above will return true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it's get checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these above functions in your code by calling them like this and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript frameworks, they usually have prepared the function for you, these are few of them:

jQuery:

 //It returns 'object';
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);

OK, let's give you this concept first before answering your question, in JavaScript Functions are object, also null, Object, Arrays and even Date, so as you see it's not simple way like typeof obj === 'object', so everything mentioned above will return true, but there are ways to check it with writing a function or using JavaScript frameworks, OK:

Now, imagine you have this object that's a real object (not null or function or array):

var obj = {obj1: 'obj1', obj2: 'obj2'};

Pure JavaScript:

//that's how it gets checked in angular framework
function isObject(obj) {
  return obj !== null && typeof obj === 'object';
}

or

//make sure the second object is capitalised 
function isObject(obj) {
   return Object.prototype.toString.call(obj) === '[object Object]';
}

or

function isObject(obj) {
    return obj.constructor.toString().indexOf("Object") > -1;
}

or

function isObject(obj) {
    return obj instanceof Object;
}

You can simply use one of these functions as above in your code by calling them and it will return true if it's an object:

isObject(obj);

If you are using a JavaScript framework, they usually have prepared these kind of functions for you, these are few of them:

jQuery:

 //It returns 'object' if real Object;
 jQuery.type(obj);

Angular:

angular.isObject(obj);

Underscore and Lodash:

//(NOTE: in Underscore and Lodash, functions, arrays return true as well but not null)
_.isObject(obj);
Source Link
Alireza
  • 105.5k
  • 27
  • 280
  • 173
Loading