Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript, is there an isObject function like isArray? [duplicate]

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?

like image 668
chris Avatar asked Oct 24 '12 08:10

chris


People also ask

How do you check an object is an array in JavaScript?

isArray() method is used to check if an object is an array. The Array. isArray() method returns true if an object is an array, otherwise returns false .

Is typeof an array?

You shouldn't use the typeof operator to check whether a value is an array, because typeof cannot distinguish between arrays and objects. Instead you should use Array. isArray() , because typeof would return 'object' , not 'array' . Array.

Is object Not array JavaScript?

You can use the JavaScript Array. isArray() method to check whether an object (or a variable) is an array or not. This method returns true if the value is an array; otherwise returns false .

Is jQuery an array?

This isArray() Method in jQuery is used to determines whether the argument is an array. Parameters: The isArray() method accepts only one parameter that is mentioned above and described below: object : This parameter is the object to test whether or not it is an array.

What is the use of isarray in JavaScript?

JavaScript isArray() The JavaScript isArray() function determines whether the value given to this function is an array or not. If this argument is correct then this function is return true, otherwise it is false.

How to determine if an object is an array in JavaScript?

The isArray() method determines whether an object is an array. This function returns true if the object is an array, and false if not.

Which method returns true if an object is an array?

The isArray () method returns true if an object is an array, otherwise false. Array.isArray () is a static property of the JavaScript Array object.

How to test if an array is static in JavaScript?

Array.isArray () is a static property of the JavaScript Array object. You can only use it as Array.isArray (). Using x.isArray (), where x is an array will return undefined. Required. An object (or any data type) to be tested.


2 Answers

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.

like image 198
bhovhannes Avatar answered Oct 03 '22 04:10

bhovhannes


use the following

It will return a true or false

theObject instanceof Object
like image 27
Doink Avatar answered Oct 03 '22 04:10

Doink