javascript, is there an isObject function like isArray?

JavascriptJqueryArraysObject

Javascript Problem Overview


> Possible Duplicate:
> Check that value is object literal?

I am working with an output that can be either null, 0, or a json object. And with that I need to come up with a means of determining if that output is indeed a real object. But I can't find anything that gives me a definitive answer as to if there is something like that in the javascript functionality or not. If there isn't is there a means otherwise that I can detect if this is an object?

Javascript Solutions


Solution 1 - Javascript

You can use typeof operator.

if( (typeof A === "object" || typeof A === 'function') && (A !== null) )
{
    alert("A is object");
}

Note that because typeof new Number(1) === 'object' while typeof Number(1) === 'number'; the first syntax should be avoided.

Solution 2 - Javascript

use the following

It will return a true or false

theObject instanceof Object

Solution 3 - Javascript

In jQuery there is $.isPlainObject() method for that:

> Description: Check to see if an object is a plain object (created > using "{}" or "new Object").

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchrisView Question on Stackoverflow
Solution 1 - JavascriptbhovhannesView Answer on Stackoverflow
Solution 2 - JavascriptDoinkView Answer on Stackoverflow
Solution 3 - JavascriptVisioNView Answer on Stackoverflow