[javascript] Check if a value is an object in JavaScript

How do you check if a value is an object in JavaScript?

This question is related to javascript types javascript-objects

The answer is


Try this

if (objectName instanceof Object == false) {
  alert('Not an object');
}
else {
  alert('An object');
}

My God, too much confusion in other answers.

Short Answer

typeof anyVar == 'object' && anyVar instanceof Object && !(anyVar instanceof Array)

To test this simply run the following statements in chrome console.

Case 1.

var anyVar = {};
typeof anyVar == 'object' && anyVar instanceof Object && !(anyVar instanceof Array) // true

Case 2.

anyVar = [];
typeof anyVar == 'object' && anyVar instanceof Object && !(anyVar instanceof Array) // false

Case 3.

anyVar = null;
typeof anyVar == 'object' && anyVar instanceof Object && !(anyVar instanceof Array); // false

Explanation

Okay.Let's break it down

typeof anyVar == 'object' is returned true from three candidates - [], {} and null,

anyVar instanceof Object narrows down these candidates to two - [], {}

!(anyVar instanceof Array) narrows to only one - {}

Drum rolls please!

By this you may have already learnt how to check for Array in Javascript.


The Ramda functional library has a wonderful function for detecting JavaScript types.

Paraphrasing the full function:

function type(val) {
  return val === null      ? 'Null'      :
         val === undefined ? 'Undefined' :
         Object.prototype.toString.call(val).slice(8, -1);
}

I had to laugh when I realized how simple and beautiful the solution was.

Example usage from Ramda documentation:

R.type({}); //=> "Object"
R.type(1); //=> "Number"
R.type(false); //=> "Boolean"
R.type('s'); //=> "String"
R.type(null); //=> "Null"
R.type([]); //=> "Array"
R.type(/[A-z]/); //=> "RegExp"
R.type(() => {}); //=> "Function"
R.type(undefined); //=> "Undefined"

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]'

For the purpose of my code I found out this decision which corresponds with some of the answers above:

ES6 variant:

const checkType = o => Object.prototype
                    .toString
                    .call(o)
                    .replace(/\[|object\s|\]/g, '')
                    .toLowerCase();

ES5 variant:

function checkType(o){
   return Object.prototype
                    .toString
                    .call(o)
                    .replace(/\[|object\s|\]/g, '')
                    .toLowerCase();
}

You can use it very simply:

checkType([]) === 'array'; // true
checkType({}) === 'object'; // true
checkType(1) === 'number'; // true
checkType('') === 'string'; // true
checkType({}.p) === 'undefined'; // true
checkType(null) === 'null'; // true

and so on..


var isArray=function(value){
    if(Array.isArray){
        return Array.isArray(value);
    }else{
        return Object.prototype.toString.call(value)==='[object Array]';
    }
}
var isObject=function(value){
    return value !== null&&!isArray(value) && typeof value === 'object';
}

var _val=new Date;
console.log(isObject(_val));//true
console.log(Object.prototype.toString.call(_val)==='[object Object]');//false

I have a code snippet that works. I find it confusing when the whole piece of code is not given, so I just created it myself:

    <!DOCTYPE html>
    <html>
    <body>
    <button onclick="myFunc()">Try it</button>

    <script>
    var abc = new Number();
    // var abc = 4;
    //this is a code variation which will give a diff alert

    function myFunc()
    {
    if(abc && typeof abc === "object")
    alert('abc is an object and does not return null value');
    else
    alert('abc is not an object');
    }
    </script>

    </body>
    </html>

const isObject = function(obj) {
  const type = typeof obj;
  return type === 'function' || type === 'object' && !!obj;
};

!!obj is shorthand for checking if obj is truthy (to filter out null)


If typeof yourVariable === 'object', it's an object or null. If you want to exclude null, just make it typeof yourVariable === 'object' && yourVariable !== null.


The most reasonable way to check the type of a value seems the typeof operator. The only problem is that it's horribly broken:

  • It returns "object" for null, which belongs to Null type.
  • It returns "function" for callable objects, which belong to Object type.
  • It can return (almost) anything it wants for non-standard non-callable objects. For example, IE seemed to like "unknown". The only forbidden results are "function" and primitive types.

typeof is only reliable for non-null primitives. So a way to check if a value is an object would be ensuring that the string returned by typeof does not correspond to a primitive, and that the object is not null. However, the problem is that a future standard could introduce a new primitive type, and our code would consider it to be an object. New types don't appear frequently, but for example ECMAScript 6 introduced the Symbol type.

Therefore, instead of typeof, I only recommend approaches whose result varies depending on if the value is an object or not. The following intends to be a

Comprehensive but not exhaustive list of proper ways to test if a value belongs to the Object type.

  • Object constructor

    The Object constructor coerces the passed argument to an object. If it's already an object, the same object is returned.

    Therefore, you can use it to coerce the value to an object, and strictly compare that object with the original value.

    The following function requires ECMAScript 3, which introduced ===:

    function isObject(value) { /* Requires ECMAScript 3 or later */
      return Object(value) === value;
    }
    

    I like this approach because it's simple and self-descriptive, and an analogous check will also work for booleans, numbers and strings. However, be aware it relies on the global Object not being shadowed nor altered.

  • Constructors

    When you instantiate a constructor, it can return a value different than the just-created instance. But that value will be ignored unless it's an object.

    The following function requires ECMAScript 3, which allowed constructors to return non-objects. Before ECMAScript 3 that threw an error, but try statements didn't exist back then.

    function isObject(value) { /* Requires ECMAScript 3 or later */
      return new function() { return value; }() === value;
    }
    

    While a bit less simple than the previous example, this one does not rely on any global property, and thus might be the safest.

  • this value

    Old ECMAScript specifications required the this value to be an object. ECMAScript 3 introduced Function.prototype.call, which allowed to call a function with an arbitrary this value, but coerced to an object.

    ECMAScript 5 introduced a strict mode which removed this behavior, but in sloppy mode we still can (but arguably shouldn't) rely on it.

    function isObject(value) { /* Requires ECMAScript 3 or later in sloppy mode */
      return function() { return this === value; }.call(value);
    }
    
  • [[Prototype]]

    All ordinary objects have an internal slot called [[Prototype]], whose value determines from which other object it inherits from. The value can only be an object or null. Therefore, you can attempt to create an object which inherits from the desired value, and check if it worked.

    Both Object.create and Object.getPrototypeOf require ECMAScript 5.

    function isObject(value) { /* Requires ECMAScript 5 or later */
      try {
        Object.create(value);
        return value !== null;
      } catch(err) {
        return false;
      }
    }
    
    function isObject(value) { /* Requires ECMAScript 5 or later */
      function Constructor() {}
      Constructor.prototype = value;
      return Object.getPrototypeOf(new Constructor()) === value;
    }
    
  • Some new ECMAScript 6 ways

    ECMAScript 6 introduces some new indirect ways to check is a value is an object. They use the previously seen approach to pass the value to some code which requires an object, wrapped inside a try statement to catch errors. Some hidden examples, not worth commenting

    _x000D_
    _x000D_
    function isObject(value) { /* Requires ECMAScript 6 or later */_x000D_
      try {_x000D_
        Object.setPrototypeOf({}, value);_x000D_
        return value !== null;_x000D_
      } catch(err) {_x000D_
        return false;_x000D_
      }_x000D_
    }
    _x000D_
    _x000D_
    _x000D_

    _x000D_
    _x000D_
    function isObject(value) { /* Requires ECMAScript 6 or later */_x000D_
      try {_x000D_
        new WeakSet([value]);_x000D_
        return true;_x000D_
      } catch(err) {_x000D_
        return false;_x000D_
      }_x000D_
    }
    _x000D_
    _x000D_
    _x000D_


Note: I intentionally skipped some approaches like Object.getPrototypeOf(value) (ES5) and Reflect methods (ES6) because they call essential internal methods which might do nasty things, e.g. if value is a proxy. For safety reasons my examples only reference value without accessing it directly.


For simply checking against Object or Array without additional function call (speed). As also posted here.

isArray()

isArray = function(a) {
    return (!!a) && (a.constructor === Array);
};
console.log(isArray(        )); // false
console.log(isArray(    null)); // false
console.log(isArray(    true)); // false
console.log(isArray(       1)); // false
console.log(isArray(   'str')); // false
console.log(isArray(      {})); // false
console.log(isArray(new Date)); // false
console.log(isArray(      [])); // true

isLiteralObject() - Note: use for Object literals only, as it returns false for custom objects, like new Date or new YourCustomObject.

isLiteralObject = function(a) {
    return (!!a) && (a.constructor === Object);
};
console.log(isLiteralObject(        )); // false
console.log(isLiteralObject(    null)); // false
console.log(isLiteralObject(    true)); // false
console.log(isLiteralObject(       1)); // false
console.log(isLiteralObject(   'str')); // false
console.log(isLiteralObject(      [])); // false
console.log(isLiteralObject(new Date)); // false
console.log(isLiteralObject(      {})); // true

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);

If you are already using AngularJS then it has a built in method which will check if its an object (without accepting null).

angular.isObject(...)

With function Array.isArray:

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

Without function Array.isArray:

Just surprised how many upvotes for wrong answers
Only 1 answer passed my tests!!! Here I've created my simplified version:

function isObject(o) {
  return o instanceof Object && o.constructor === Object;
}

As for me, it's clear and simple, and just works! Here my tests:

console.log(isObject({}));             // Will return: true
console.log(isObject([]));             // Will return: false
console.log(isObject(null));           // Will return: false
console.log(isObject(/.*/));           // Will return: false
console.log(isObject(function () {})); // Will return: false

ONE MORE TIME: not all answers pass this tests !!!


In case you need to verify that object is instance of particular class you have to check constructor with your particular class, like:

function isDate(o) {
  return o instanceof Object && o.constructor === Date;
}

simple test:

var d = new Date();
console.log(isObject(d)); // Will return: false
console.log(isDate(d));   // Will return: true

As result, you will have strict and robust code!


In case you won't create functions like isDate, isError, isRegExp, etc you may consider option to use this generalized functions:

function isObject(o) {
  return o instanceof Object && typeof o.constructor === 'function';
}

it won't work correctly for all test cases mentioned earlier, but it's good enough for all objects (plain or constructed).


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 v1 based on this implementation! And it works for all earlier described test cases!


Consider - typeof bar === "object" to determine if bar is an object

Although typeof bar === "object" is a reliable way of checking if bar is an object, the surprising gotcha in JavaScript is that null is also considered an object!

Therefore, the following code will, to the surprise of most developers, log true (not false) to the console:

var bar = null; console.log(typeof bar === "object"); // logs true! As long as one is aware of this, the problem can easily be avoided by also checking if bar is null:

console.log((bar !== null) && (typeof bar === "object")); // logs false To be entirely thorough in our answer, there are two other things worth noting:

First, the above solution will return false if bar is a function. In most cases, this is the desired behavior, but in situations where you want to also return true for functions, you could amend the above solution to be:

console.log((bar !== null) && ((typeof bar === "object") || (typeof bar === "function"))); Second, the above solution will return true if bar is an array (e.g., if var bar = [];). In most cases, this is the desired behavior, since arrays are indeed objects, but in situations where you want to also false for arrays, you could amend the above solution to be:

console.log((bar !== null) && (typeof bar === "object") && (toString.call(bar) !== "[object Array]")); However, there’s one other alternative that returns false for nulls, arrays, and functions, but true for objects:

console.log((bar !== null) && (bar.constructor === Object)); Or, if you’re using jQuery:

console.log((bar !== null) && (typeof bar === "object") && (! $.isArray(bar)));

ES5 makes the array case quite simple, including its own null check:

console.log(Array.isArray(bar));


you can just use JSON.stringify to test your Object, like this:

_x000D_
_x000D_
var test = {}_x000D_
if(JSON.stringify(test)[0] === '{') {_x000D_
  console.log('this is a Object')_x000D_
}
_x000D_
_x000D_
_x000D_


Ready to use functions for checking

function isObject(o) {
  return null != o && 
    typeof o === 'object' && 
    Object.prototype.toString.call(o) === '[object Object]';
}

function isDerivedObject(o) {
  return !isObject(o) && 
    null != o && 
    (typeof o === 'object' || typeof o === 'function') &&
    /^\[object /.test(Object.prototype.toString.call(o));
}

// Loose equality operator (==) is intentionally used to check
// for undefined too

// Also note that, even null is an object, within isDerivedObject
// function we skip that and always return false for null

Explanation

  • In Javascript, null, Object, Array, Date and functions are all objects. Although, null is bit contrived. So, it's better to check for the null first, to detect it's not null.

  • Checking for typeof o === 'object' guarantees that o is an object. Without this check, Object.prototype.toString would be meaningless, since it would return object for everthing, even for undefined and null! For example: toString(undefined) returns [object Undefined]!

    After typeof o === 'object' check, toString.call(o) is a great method to check whether o is an object, a derived object like Array, Date or a function.

  • In isDerivedObject function, it checks for the o is a function. Because, function also an object, that's why it's there. If it didn't do that, function will return as false. Example: isDerivedObject(function() {}) would return false, however now it returns true.

  • One can always change the definition of what is an object. So, one can change these functions accordingly.


Tests

_x000D_
_x000D_
function isObject(o) {_x000D_
  return null != o && _x000D_
    typeof o === 'object' && _x000D_
    Object.prototype.toString.call(o) === '[object Object]';_x000D_
}_x000D_
_x000D_
function isDerivedObject(o) {_x000D_
  return !isObject(o) && _x000D_
    null != o && _x000D_
    (typeof o === 'object' || typeof o === 'function') &&_x000D_
    /^\[object /.test(Object.prototype.toString.call(o));_x000D_
}_x000D_
_x000D_
// TESTS_x000D_
_x000D_
// is null an object?_x000D_
_x000D_
console.log(_x000D_
  'is null an object?', isObject(null)_x000D_
);_x000D_
_x000D_
console.log(_x000D_
  'is null a derived object?', isDerivedObject(null)_x000D_
);_x000D_
_x000D_
// is 1234 an object?_x000D_
_x000D_
console.log(_x000D_
  'is 1234 an object?', isObject(1234)_x000D_
);_x000D_
_x000D_
console.log(_x000D_
  'is 1234 a derived object?', isDerivedObject(1234)_x000D_
);_x000D_
_x000D_
// is new Number(1234) an object?_x000D_
_x000D_
console.log(_x000D_
  'is new Number(1234) an object?', isObject(new Number(1234))_x000D_
);_x000D_
_x000D_
console.log(_x000D_
  'is new Number(1234) a derived object?', isDerivedObject(1234)_x000D_
);_x000D_
_x000D_
// is function object an object?_x000D_
_x000D_
console.log(_x000D_
  'is (new (function (){})) an object?', _x000D_
  isObject((new (function (){})))_x000D_
);_x000D_
_x000D_
console.log(_x000D_
  'is (new (function (){})) a derived object?', _x000D_
  isObject((new (function (){})))_x000D_
);_x000D_
_x000D_
// is {} an object?_x000D_
_x000D_
console.log(_x000D_
  'is {} an object?', isObject({})_x000D_
);_x000D_
_x000D_
console.log(_x000D_
  'is {} a derived object?', isDerivedObject({})_x000D_
);_x000D_
_x000D_
// is Array an object?_x000D_
_x000D_
console.log(_x000D_
  'is Array an object?',_x000D_
  isObject([])_x000D_
)_x000D_
_x000D_
console.log(_x000D_
  'is Array a derived object?',_x000D_
  isDerivedObject([])_x000D_
)_x000D_
_x000D_
// is Date an object?_x000D_
_x000D_
console.log(_x000D_
  'is Date an object?', isObject(new Date())_x000D_
);_x000D_
_x000D_
console.log(_x000D_
  'is Date a derived object?', isDerivedObject(new Date())_x000D_
);_x000D_
_x000D_
// is function an object?_x000D_
_x000D_
console.log(_x000D_
  'is function an object?', isObject(function(){})_x000D_
);_x000D_
_x000D_
console.log(_x000D_
  'is function a derived object?', isDerivedObject(function(){})_x000D_
);
_x000D_
_x000D_
_x000D_


Here's an answer with optional chaining, and perhaps the smallest isObj function for this question.

_x000D_
_x000D_
const isObj = o => o?.constructor === Object;_x000D_
_x000D_
// True for this_x000D_
console.log(isObj({}));        // object!_x000D_
_x000D_
// False for these_x000D_
console.log(isObj(0));         // number_x000D_
console.log(isObj([]));        // array_x000D_
console.log(isObj('lol'));     // string_x000D_
console.log(isObj(null));      // null_x000D_
console.log(isObj(undefined)); // undefined_x000D_
console.log(isObj(() => {}));  // function_x000D_
console.log(isObj(Object));    // class
_x000D_
_x000D_
_x000D_


Little late... for "plain objects" (i mean, like {'x': 5, 'y': 7}) i have this little snippet:

function isPlainObject(o) {
   return (o === null || Array.isArray(o) || typeof o == 'function' || o.constructor === Date ) ?
           false
          :(typeof o == 'object');
}

It generates the next output:

console.debug(isPlainObject(isPlainObject)); //function, false
console.debug(isPlainObject({'x': 6, 'y': 16})); //literal object, true
console.debug(isPlainObject(5)); //number, false
console.debug(isPlainObject(undefined)); //undefined, false
console.debug(isPlainObject(null)); //null, false
console.debug(isPlainObject('a')); //string, false
console.debug(isPlainObject([])); //array?, false
console.debug(isPlainObject(true)); //bool, false
console.debug(isPlainObject(false)); //bool, false

It always works for me. If will return "true" only if the type of "o" is "object", but no null, or array, or function. :)


underscore.js provides the following method to find out if something is really an object:

_.isObject = function(obj) {
  return obj === Object(obj);
};

UPDATE

Because of a previous bug in V8 and minor micro speed optimization, the method looks as follows since underscore.js 1.7.0 (August 2014):

_.isObject = function(obj) {
  var type = typeof obj;
  return type === 'function' || type === 'object' && !!obj;
};

use typeof(my_obj) will tells which type of variable it is.

for Array: Array.isArray(inp) or [] isinstanceof Array

if it is object will show 'object'

simple JS function,

function isObj(v) {
    return typeof(v) == "object"
}

Eg:

_x000D_
_x000D_
function isObj(v) {_x000D_
    return typeof(v) == "object"_x000D_
}_x000D_
_x000D_
var samp_obj = {_x000D_
   "a" : 1,_x000D_
   "b" : 2,_x000D_
   "c" : 3_x000D_
}_x000D_
_x000D_
var num = 10;_x000D_
var txt = "Hello World!"_x000D_
var_collection = [samp_obj, num, txt]_x000D_
for (var i in var_collection) {_x000D_
  if(isObj(var_collection[i])) {_x000D_
     console.log("yes it is object")_x000D_
  }_x000D_
  else {_x000D_
     console.log("No it is "+ typeof(var_collection[i]))_x000D_
  }_x000D_
}
_x000D_
_x000D_
_x000D_


i found a "new" way to do just this kind of type checking from this SO question: Why does instanceof return false for some literals?

from that, i created a function for type checking as follows:

function isVarTypeOf(_var, _type){
    try {
        return _var.constructor === _type;
    } catch(ex) {
        return false;         //fallback for null or undefined
    }
}

then you can just do:

console.log(isVarTypeOf('asdf', String));   // returns true
console.log(isVarTypeOf(new String('asdf'), String));   // returns true
console.log(isVarTypeOf(123, String));   // returns false
console.log(isVarTypeOf(123, Number));   // returns true
console.log(isVarTypeOf(new Date(), String));   // returns false
console.log(isVarTypeOf(new Date(), Number));   // returns false
console.log(isVarTypeOf(new Date(), Date));   // returns true
console.log(isVarTypeOf([], Object));   // returns false
console.log(isVarTypeOf([], Array));   // returns true
console.log(isVarTypeOf({}, Object));   // returns true
console.log(isVarTypeOf({}, Array));   // returns false
console.log(isVarTypeOf(null, Object));   // returns false
console.log(isVarTypeOf(undefined, Object));   // returns false
console.log(isVarTypeOf(false, Boolean));   // returns true

this is tested on Chrome 56, Firefox 52, Microsoft Edge 38, Internet Explorer 11, Opera 43

edit:
if you also want to check if a variable is null or undefined, you can use this instead:

function isVarTypeOf(_var, _type){
    try {
        return _var.constructor === _type;
    } catch(ex) {
        return _var == _type;   //null and undefined are considered the same
        // or you can use === if you want to differentiate them
    }
}

var a = undefined, b = null;
console.log(isVarTypeOf(a, undefined)) // returns true
console.log(isVarTypeOf(b, undefined)) // returns true
console.log(isVarTypeOf(a, null)) // returns true

update from inanc's comment: challenge accepted :D

if you want to loose compare objects you can try this way:

function isVarTypeOf(_var, _type, looseCompare){
    if (!looseCompare){
        try {
            return _var.constructor === _type;
        } catch(ex){
            return _var == _type;
        }
    } else {
        try{
            switch(_var.constructor){
                case Number:
                case Function:
                case Boolean:
                case Symbol:
                case Date:
                case String:
                case RegExp:
                    // add all standard objects you want to differentiate here
                    return _var.constructor === _type;
                case Error:
                case EvalError:
                case RangeError:
                case ReferenceError:
                case SyntaxError:
                case TypeError:
                case URIError:
                    // all errors are considered the same when compared to generic Error
                    return (_type === Error ? Error : _var.constructor) === _type;
                case Array:
                case Int8Array:
                case Uint8Array:
                case Uint8ClampedArray:
                case Int16Array:
                case Uint16Array:
                case Int32Array:
                case Uint32Array:
                case Float32Array:
                case Float64Array:
                    // all types of array are considered the same when compared to generic Array
                    return (_type === Array ? Array : _var.constructor) === _type;
                case Object:
                default:
                    // the remaining are considered as custom class/object, so treat it as object when compared to generic Object
                    return (_type === Object ? Object : _var.constructor) === _type;
            }
        } catch(ex){
            return _var == _type;   //null and undefined are considered the same
            // or you can use === if you want to differentiate them
        }
    }
}

that way, you can do just like inanc's comment:

isVarTypeOf(new (function Foo(){}), Object); // returns false
isVarTypeOf(new (function Foo(){}), Object, true); // returns true

or

Foo = function(){};
Bar = function(){};
isVarTypeOf(new Foo(), Object);   // returns false
isVarTypeOf(new Foo(), Object, true);   // returns true
isVarTypeOf(new Bar(), Foo, true);   // returns false
isVarTypeOf(new Bar(), Bar, true);   // returns true
isVarTypeOf(new Bar(), Bar);    // returns true

var a = [1]
typeof a //"object"
a instanceof Object //true
a instanceof Array //true

var b ={a: 1}
b instanceof Object //true
b instanceof Array //false

var c = null
c instanceof Object //false
c instanceof Array //false

I was asked to provide more details. Most clean and understandable way of checking if our variable is an object is typeof myVar. It returns a string with a type (e.g. "object", "undefined").

Unfortunately either Array and null also have a type object. To take only real objects there is a need to check inheritance chain using instanceof operator. It will eliminate null, but Array has Object in inheritance chain.

So the solution is:

if (myVar instanceof Object && !(myVar instanceof Array)) {
  // code for objects
}

I'm fond of simply:

function isObject (item) {
  return (typeof item === "object" && !Array.isArray(item) && item !== null);
}

If the item is a JS object, and it's not a JS array, and it's not null…if all three prove true, return true. If any of the three conditions fails, the && test will short-circuit and false will be returned. The null test can be omitted if desired (depending on how you use null).

DOCS:

http://devdocs.io/javascript/operators/typeof

http://devdocs.io/javascript/global_objects/object

http://devdocs.io/javascript/global_objects/array/isarray

http://devdocs.io/javascript/global_objects/null


Mostly typeof obj[index] === 'object'is used, but it will return also function and #document which are an objects. It depends up to you if it need to be included in the result.

Basically you can do a test code that filtering out if a particular elements is an object by checking the output in your console. Here you can run a code just for a sample:

_x000D_
_x000D_
function cekObject(obj, index) {  _x000D_
  if (!obj.tagName) {_x000D_
_x000D_
    //test case #1      _x000D_
    if (typeof obj === 'object') {_x000D_
      console.log('obj['+ index +'] is listed as an object');_x000D_
    } _x000D_
    _x000D_
  }_x000D_
}
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>_x000D_
<script>_x000D_
  function updateFilters() {_x000D_
    var object = $('.j-image');_x000D_
    $('.juicer-feed').empty();_x000D_
    _x000D_
    for(var index in object) {_x000D_
      cekObject(object[index], index);_x000D_
    }; _x000D_
  }_x000D_
</script>_x000D_
_x000D_
<ul class="juicer-feed" data-feed-id="chetabahana" data-after="updateFilters()"></ul>_x000D_
<script src="https://assets.juicer.io/embed.js"></script>
_x000D_
_x000D_
_x000D_


If explicitly want to check if the given value is {}.

function isObject (value) {
 return value && typeof value === 'object' && value.constructor === Object;
}

You can do this easily with toString() method of Object.prototype

if(Object.prototype.toString.call(variable) == "[object Object]"){
   doSomething();
}

or

if(Object.prototype.toString.call(variable).slice(8,-1).toLowerCase() == "object"){
   doSomething();
}

Let's define "object" in Javascript. According to the MDN docs, every value is either an object or a primitive:

primitive, primitive value

A data that is not an object and does not have any methods. JavaScript has 5 primitive datatypes: string, number, boolean, null, undefined.

What's a primitive?

  • 3
  • 'abc'
  • true
  • null
  • undefined

What's an object (i.e. not a primitive)?

  • Object.prototype
  • everything descended from Object.prototype
    • Function.prototype
      • Object
      • Function
      • function C(){} -- user-defined functions
    • C.prototype -- the prototype property of a user-defined function: this is not Cs prototype
      • new C() -- "new"-ing a user-defined function
    • Math
    • Array.prototype
      • arrays
    • {"a": 1, "b": 2} -- objects created using literal notation
    • new Number(3) -- wrappers around primitives
    • ... many other things ...
  • Object.create(null)
  • everything descended from an Object.create(null)

How to check whether a value is an object

instanceof by itself won't work, because it misses two cases:

// oops:  isObject(Object.prototype) -> false
// oops:  isObject(Object.create(null)) -> false
function isObject(val) {
    return val instanceof Object; 
}

typeof x === 'object' won't work, because of false positives (null) and false negatives (functions):

// oops: isObject(Object) -> false
function isObject(val) {
    return (typeof val === 'object');
}

Object.prototype.toString.call won't work, because of false positives for all of the primitives:

> Object.prototype.toString.call(3)
"[object Number]"

> Object.prototype.toString.call(new Number(3))
"[object Number]"

So I use:

function isObject(val) {
    if (val === null) { return false;}
    return ( (typeof val === 'function') || (typeof val === 'object') );
}

@Daan's answer also seems to work:

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

because, according to the MDN docs:

The Object constructor creates an object wrapper for the given value. If the value is null or undefined, it will create and return an empty object, otherwise, it will return an object of a type that corresponds to the given value. If the value is an object already, it will return the value.


A third way that seems to work (not sure if it's 100%) is to use Object.getPrototypeOf which throws an exception if its argument isn't an object:

// these 5 examples throw exceptions
Object.getPrototypeOf(null)
Object.getPrototypeOf(undefined)
Object.getPrototypeOf(3)
Object.getPrototypeOf('abc')
Object.getPrototypeOf(true)

// these 5 examples don't throw exceptions
Object.getPrototypeOf(Object)
Object.getPrototypeOf(Object.prototype)
Object.getPrototypeOf(Object.create(null))
Object.getPrototypeOf([])
Object.getPrototypeOf({})

After reading and trying out a lot of implementations, I've noticed that very few people try to check for values like JSON, Math, document or objects with prototype chains longer than 1 step.

Instead of checking the typeof of our variable and then hacking away edge-cases, I thought it'd be better if the check is kept as simple as possible to avoid having to refactor when there's new primitives or native objects added that register as typeof of 'object'.

After all, the typeof operator will tell you if something is an object to JavaScript, but JavaScript's definition of an object is too broad for most real-world scenarios (e.g. typeof null === 'object'). Below is a function that determines whether variable v is an object by essentially repeating two checks:

  1. A loop is started that continues as long as the stringified version of v is '[object Object]'.
    I wanted the result of the function to be exactly like the logs below, so this is the only "objectness"-criteria I ended up with. If it fails, the function returns false right away.
  2. v is replaced with the next prototype in the chain with v = Object.getPrototypeOf(v), but also directly evaluated after. When the new value of v is null, it means that every prototype including the root prototype (which could very well have been the only prototype inside the chain) have passed the check in the while loop and we can return true. Otherwise, a new iteration starts.

_x000D_
_x000D_
function isObj (v) {_x000D_
  while (     Object.prototype.toString.call(v) === '[object Object]')_x000D_
  if    ((v = Object.getPrototypeOf(v))         === null)_x000D_
  return true_x000D_
  return false_x000D_
}_x000D_
_x000D_
console.log('FALSE:')_x000D_
console.log('[]                   -> ', isObj([]))_x000D_
console.log('null                 -> ', isObj(null))_x000D_
console.log('document             -> ', isObj(document))_x000D_
console.log('JSON                 -> ', isObj(JSON))_x000D_
console.log('function             -> ', isObj(function () {}))_x000D_
console.log('new Date()           -> ', isObj(new Date()))_x000D_
console.log('RegExp               -> ', isObj(/./))_x000D_
_x000D_
console.log('TRUE:')_x000D_
console.log('{}                   -> ', isObj({}))_x000D_
console.log('new Object()         -> ', isObj(new Object()))_x000D_
console.log('new Object(null)     -> ', isObj(new Object(null)))_x000D_
console.log('new Object({})       -> ', isObj(new Object({foo: 'bar'})))_x000D_
console.log('Object.prototype     -> ', isObj(Object.prototype))_x000D_
console.log('Object.create(null)  -> ', isObj(Object.create(null)))_x000D_
console.log('Object.create({})    -> ', isObj(Object.create({foo: 'bar'})))_x000D_
console.log('deep inheritance     -> ', isObj(Object.create(Object.create({foo: 'bar'}))))
_x000D_
_x000D_
_x000D_


The simplest way to determine if a variable is an Object or not:

first: Evaluate the type of Object

second: Getting an Array property from an Object must returns undefined (For example length is an Array property which does not work on Object)

so:

if (_object instanceof Object && _object.length === undefined) {
// here you can be sure that you have a curly bracket object :)
}

Oh My God! I think this could be more shorter than ever, let see this:

Short and Final code

_x000D_
_x000D_
function isObject(obj)_x000D_
{_x000D_
    return obj != null && obj.constructor.name === "Object"_x000D_
}_x000D_
_x000D_
console.log(isObject({})) // returns true_x000D_
console.log(isObject([])) // returns false_x000D_
console.log(isObject(null)) // returns false
_x000D_
_x000D_
_x000D_

Explained

Return Types

typeof JavaScript objects (including null) returns "object"

_x000D_
_x000D_
console.log(typeof null, typeof [], typeof {})
_x000D_
_x000D_
_x000D_

Checking on Their constructors

Checking on their constructor property returns function with their names.

_x000D_
_x000D_
console.log(({}).constructor) // returns a function with name "Object"_x000D_
console.log(([]).constructor) // returns a function with name "Array"_x000D_
console.log((null).constructor) //throws an error because null does not actually have a property
_x000D_
_x000D_
_x000D_

Introducing Function.name

Function.name returns a readonly name of a function or "anonymous" for closures.

_x000D_
_x000D_
console.log(({}).constructor.name) // returns "Object"_x000D_
console.log(([]).constructor.name) // returns "Array"_x000D_
console.log((null).constructor.name) //throws an error because null does not actually have a property
_x000D_
_x000D_
_x000D_

Note: As of 2018, Function.name might not work in IE https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name#Browser_compatibility


if(typeof value === 'object' && value.constructor === Object)
{
    console.log("This is an object");
}

What I like to use is this

function isObject (obj) {
  return typeof(obj) == "object" 
        && !Array.isArray(obj) 
        && obj != null 
        && obj != ""
        && !(obj instanceof String)  }

I think in most of the cases a Date must pass the check as an Object, so I do not filter dates out


I know it's old, but I do think this solution is interesting if you don't care about the property order:

_x000D_
_x000D_
function objectsDeeplyEqual(obj1, obj2) {_x000D_
  const keys1 = Object.keys(obj1);_x000D_
  const keys2 = Object.keys(obj2);_x000D_
  let equal = true;_x000D_
  if (keys1.length !== keys2.length) {_x000D_
    return false;_x000D_
  }_x000D_
  for (let i = 0; i < keys1.length && equal; i++) {_x000D_
    if (obj1[keys1[i]] instanceof Object && obj2[keys1[i]] instanceof Object) {_x000D_
      equal = equal && isDeeplyEqual(obj1[keys1[i]], obj2[keys1[i]]);_x000D_
    } else {_x000D_
      equal = equal && obj1[keys1[i]] === obj2[keys1[i]];_x000D_
    }_x000D_
  }_x000D_
  return equal;_x000D_
}_x000D_
_x000D_
var a = {_x000D_
  a: true,_x000D_
  b: 'asd',_x000D_
  c: {_x000D_
    a: true,_x000D_
    b: 'asd',_x000D_
    c: {_x000D_
      a: true,_x000D_
      b: 'asd',_x000D_
    },_x000D_
  },_x000D_
};_x000D_
_x000D_
var b = {_x000D_
  a: true,_x000D_
  c: {_x000D_
    a: true,_x000D_
    b: 'asd',_x000D_
    c: {_x000D_
      a: true,_x000D_
      b: 'asd',_x000D_
    },_x000D_
  },_x000D_
  b: 'asd',_x000D_
};_x000D_
_x000D_
console.log(isDeeplyEqual(a,b));_x000D_
console.log(isDeeplyEqual(b,a));
_x000D_
_x000D_
_x000D_


Performance

Today 2020.09.26 I perform tests on MacOs HighSierra 10.13.6 on Chrome v85, Safari v13.1.2 and Firefox v80 for chosen solutions.

Results

  • solutions C and H are fast/fastest on all browsers for all cases
  • solutions D and G are slow/slowest on all browsers for all cases

enter image description here

Details

I perform 3 tests cases for solutions A B C D E F G H I J K L M N O P Q R S T U V

  • for small object - you can run it HERE
  • for big object - you can run it HERE
  • for no object - you can run it HERE

Below snippet presents differences between solutions. Solutions A-G give proper answers for chosen cases described by Matt Fenwick

_x000D_
_x000D_
// https://stackoverflow.com/a/14706877/860099
function A(x) {
  return x === Object(x);
};

// https://stackoverflow.com/a/42250981/860099
function B(x) {
    return _.isObject(x);
}

// https://stackoverflow.com/a/34864175/860099
function C(x) {
    return x != null && (typeof x === 'object' || typeof x === 'function');
}

// https://stackoverflow.com/a/39187058/860099
function D(x) { 
  return new function() { return x; }() === x;
}

// https://stackoverflow.com/a/39187058/860099
function E(x) { 
  return function() { return this === x; }.call(x);
}

// https://stackoverflow.com/a/39187058/860099
function F(x) { /* Requires ECMAScript 5 or later */
  try {
    Object.create(x);
    return x !== null;
  } catch(err) {
    return false;
  }
}

// https://stackoverflow.com/a/39187058/860099
function G(x) { /* Requires ECMAScript 5 or later */
  function Constructor() {}
  Constructor.prototype = x;
  return Object.getPrototypeOf(new Constructor()) === x;
}

// https://stackoverflow.com/a/8511332/860099
function H(x) {
  return typeof x === 'object' && x !== null
}

// https://stackoverflow.com/a/25715455/860099
function I(x) {
  return (typeof x === "object" && !Array.isArray(x) && x !== null);
};

// https://stackoverflow.com/a/22482737/860099
function J(x) {
  return x instanceof Object; 
}

// https://stackoverflow.com/a/50712057/860099
function K(x)
{
    let t= JSON.stringify(x);
    return t ? t[0] === '{' : false;
}

// https://stackoverflow.com/a/13356338/860099
function L(x) {
  return Object.prototype.toString.call(x) === "[object Object]";
};



// https://stackoverflow.com/a/46663081/860099
function M(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;
}

// https://stackoverflow.com/a/42250981/860099
function N(x) {
    return $.type(x) === 'object';
}

// https://stackoverflow.com/a/34864175/860099
function O(x) {
    if (Object.prototype.toString.call(x) !== '[object Object]') {
        return false;
    } else {
        var prototype = Object.getPrototypeOf(x);
        return prototype === null || prototype === Object.prototype;
    }
}

// https://stackoverflow.com/a/57863169/860099
function P(x) {
  while (     Object.prototype.toString.call(x) === '[object Object]')
  if    ((x = Object.getPrototypeOf(x))         === null)
  return true
  return false
}

// https://stackoverflow.com/a/43289971/860099
function Q(x){
  try{
    switch(x.constructor){
      case Number:
      case Function:
      case Boolean:
      case Symbol:
      case Date:
      case String:
      case RegExp:
        return x.constructor === Object;
      case Error:
      case EvalError:
      case RangeError:
      case ReferenceError:
      case SyntaxError:
      case TypeError:
      case URIError:
        return (Object === Error ? Error : x.constructor) === Object;
      case Array:
      case Int8Array:
      case Uint8Array:
      case Uint8ClampedArray:
      case Int16Array:
      case Uint16Array:
      case Int32Array:
      case Uint32Array:
      case Float32Array:
      case Float64Array:
        return (Object === Array ? Array : x.constructor) === Object;
      case Object:
      default:
        return (Object === Object ? Object : x.constructor) === Object;
    }
  } catch(ex){
    return x == Object;   
  }
}

// https://stackoverflow.com/a/52478680/860099
function R(x) {
    return typeof x == 'object' && x instanceof Object && !(x instanceof Array);
}

// https://stackoverflow.com/a/51458052/860099
function S(x)
{
    return x != null && x.constructor?.name === "Object"
}

// https://stackoverflow.com/a/42250981/860099
function T(x) {
    return x?.constructor?.toString().indexOf("Object") > -1;
}

// https://stackoverflow.com/a/43223661/860099
function U(x)
{
    return x?.constructor === Object;
}

// https://stackoverflow.com/a/46663081/860099
function V(x) {
  return x instanceof Object && x.constructor === Object;
}




// -------------
// TEST
// -------------

console.log('column: 1 2 3 4 5 6 - 7 8 9 10 11');

[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V]
.map(f=> console.log(`${f.name}:      ${1*f(new Date())} ${1*f(/./)} ${1*f({})} ${1*f(Object.prototype)} ${1*f(Object.create(null))} ${1*f(()=>{})} - ${1*f("abc")} ${1*f(3)} ${1*f(true)}  ${1*f(null)}  ${1*f(undefined)}`))

console.log(`
Columns legend (test cases):
 1: new Date()
 2: /./ (RegExp)
 3: {}
 4: Object.prototype
 5: Object.create(null)
 6: ()=>{} (function)
 7: "abc" (string)
 8: 3 (number)
 9: true (boolean)
10: null
11: undefined

Rows:
1 = is object
0 = is NOT object

Theoretically columns 1-6 should have have 1, columns 7-11 shoud have 0
`);
_x000D_
<script
  src="https://code.jquery.com/jquery-3.5.1.min.js"
  integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
  crossorigin="anonymous"></script>
  
<script 
  src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js" 
  integrity="sha512-90vH1Z83AJY9DmlWa8WkjkV79yfS2n2Oxhsi2dZbIv0nC4E6m5AbH8Nh156kkM7JePmqD6tcZsfad1ueoaovww==" 
  crossorigin="anonymous"></script>
  
This shippet only presents functions used in performance tests - it not perform tests itself!
_x000D_
_x000D_
_x000D_

And here are example results for chrome

enter image description here


This will work. It is a function that returns true, false, or possibly null.

_x000D_
_x000D_
const isObject = obj => obj && obj.constructor && obj.constructor === Object;_x000D_
_x000D_
console.log(isObject({})); // true_x000D_
console.log(isObject([])); // false_x000D_
console.log(isObject(new Function)); // false_x000D_
console.log(isObject(new Number(123))); // false_x000D_
console.log(isObject(null)); // null
_x000D_
_x000D_
_x000D_


Since there seems a lot of confusion about how to handle this problem correctly, I'll leave my 2 cents (this answer is spec compliant and produces correct results under all circumstances):

Testing for primitives: undefined null boolean string number

function isPrimitive(o){return typeof o!=='object'||null}

An object is not a primitive:

function isObject(o){return !isPrimitive(o)}

Or alternatively:

function isObject(o){return o instanceof Object}
function isPrimitive(o){return !isObject(o)}

Testing for any Array:

const isArray=(function(){
    const arrayTypes=Object.create(null);
    arrayTypes['Array']=true;
    arrayTypes['Int8Array']=true;
    arrayTypes['Uint8Array']=true;
    arrayTypes['Uint8ClampedArray']=true;
    arrayTypes['Int16Array']=true;
    arrayTypes['Uint16Array']=true;
    arrayTypes['Int32Array']=true;
    arrayTypes['Uint32Array']=true;
    arrayTypes['BigInt64Array']=true;
    arrayTypes['BigUint64Array']=true;
    arrayTypes['Float32Array']=true;
    arrayTypes['Float64Array']=true;
    return function(o){
        if (!o) return false;
        return !isPrimitive(o)&&!!arrayTypes[o.constructor.name];
    }
}());

Testing for object excluding: Date RegExp Boolean Number String Function any Array

const isObjectStrict=(function(){
    const nativeTypes=Object.create(null);
    nativeTypes['Date']=true;
    nativeTypes['RegExp']=true;
    nativeTypes['Boolean']=true;
    nativeTypes['Number']=true;
    nativeTypes['String']=true;
    nativeTypes['Function']=true;
    return function(o){
        if (!o) return false;
        return !isPrimitive(o)&&!isArray(o)&&!nativeTypes[o.constructor.name];
    }
}());

function isObjectLike(value) {
  return value != null && typeof value == 'object';
}

got from lodash


A little NodeJS console experiment based on the reading of Matt Fenwick's third option to his complete answer above. Just a little tweak to get true or false.

The following return false for the object test.

> if(Object.getPrototypeOf('v') === Object.prototype){console.log(true);}else{console.log(false);}
false
undefined
> if(Object.getPrototypeOf(1) === Object.prototype){console.log(true);}else{console.log(false);}
false
undefined
> if(Object.getPrototypeOf(false) === Object.prototype){console.log(true);}else{console.log(false);}
false
undefined
> if(Object.getPrototypeOf(['apple']) === Object.prototype){console.log(true);}else{console.log(false);}
false
undefined

The object will return true.

> if(Object.getPrototypeOf({'this':10}) === Object.prototype){console.log(true);}else{console.log(false);}
true
undefined

lodash has isPlainObject, which might be what many who come to this page are looking for. It returns false when give a function or array.


Object.prototype.toString.call(myVar) will return:

  • "[object Object]" if myVar is an object
  • "[object Array]" if myVar is an array
  • etc.

For more information on this and why it is a good alternative to typeof, check out this article.


Remember guys that typeof new Date() is "object".

So if you're looking for { key: value } objects, a date object is invalid.

Finally then: o => o && typeof o === 'object' && !(o instanceof Date) is a better answer to your question in my opinion.


It depends on what you mean with "is an object". If you want everything that is not a primitive, i.e. things that you can set new properties on, this should do the trick:

function isAnyObject(value) {
    return value != null && (typeof value === 'object' || typeof value === 'function');
}

It excludes the primitives (plain numbers/NaN/Infinity, plain strings, symbols, true/false, undefined and null) but should return true for everything else (including Number, Boolean and String objects). Note that JS does not define what "host" objects, such as window or console, should return when used with typeof, so those are hard to cover with a check like this.

If you want to know whether something is a "plain" object, i.e. it was created as a literal {} or with Object.create(null), you might do this:

function isPlainObject(value) {
    if (Object.prototype.toString.call(value) !== '[object Object]') {
        return false;
    } else {
        var prototype = Object.getPrototypeOf(value);
        return prototype === null || prototype === Object.prototype;
    }
}

Edit 2018: Because Symbol.toStringTag now allows customizing the output of Object.prototype.toString.call(...), the isPlainObject function above might return false in some cases even when the object started its life as a literal. Arguably, by convention an object with a custom string tag isn't exactly a plain object any more, but this has further muddied the definition of what a plain object even is in Javascript.


direct answer is ofcourse typeof v==='object' but this is terribly not useful. I wonder if the OP meant a plain dictionary ..

try:

isdict(v) { return  v !== undefined && v!==null && typeof v==='object' && v.constructor!==Array && v.constructor!==Date; }

It is an old question but thought to leave this here. Most people are checking if the variable is {} meaning a key-value paired and not what is the underline construct that JavaScript is using for a given thing, cuz to be honest mostly everything in JavaScript is an object. So taking that out of the way. If you do...

let x = function() {}
typeof x === 'function' //true
x === Object(x) // true
x = []
x === Object(x) // true

// also
x = null
typeof null // 'object'

Most of the time what we want is to know if we have a resource object from an API or our database call returned from the ORM. We can then test if is not an Array, is not null, is not typeof 'function', and is an Object

// To account also for new Date() as @toddmo pointed out

x instanceof Object && x.constructor === Object

x = 'test' // false
x = 3 // false
x = 45.6 // false
x = undefiend // false
x = 'undefiend' // false
x = null // false
x = function(){} // false
x = [1, 2] // false
x = new Date() // false
x = {} // true

Its depends on use-case, if we do not want to allow array and functions to be an Object, we can use the underscore.js builtin functions.

    function xyz (obj) { 
       if (_.isObject(obj) && !_.isFunction(obj) && !_.isArray(obj)) {
         // now its sure that obj is an object 
       } 
    }

When everything else fails, I use this:

var isObject = function(item) {
   return item.constructor.name === "Object";
}; 

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to types

Cannot invoke an expression whose type lacks a call signature How to declare a Fixed length Array in TypeScript Typescript input onchange event.target.value Error: Cannot invoke an expression whose type lacks a call signature Class constructor type in typescript? What is dtype('O'), in pandas? YAML equivalent of array of objects in JSON Converting std::__cxx11::string to std::string Append a tuple to a list - what's the difference between two ways? How to check if type is Boolean

Examples related to javascript-objects

Cannot read property 'style' of undefined -- Uncaught Type Error Is this a good way to clone an object in ES6? What’s the difference between “{}” and “[]” while declaring a JavaScript array? Comparing two arrays of objects, and exclude the elements who match values into new array in JS Converting JavaScript object with numeric keys into array From an array of objects, extract value of a property as array How to copy JavaScript object to new variable NOT by reference? Remove property for all objects in array Using curl POST with variables defined in bash script functions How to sum the values of a JavaScript object?