Testing for an empty object in Javascript
Posted on: February 18, 2021 by Prince Chukwudire
In this guide, we will write a check for an empty object in JavaScript. To achieve this we would be using the custom built-in object.keys
method.
let emptyObject = {};
Object.keys(emptyObject ).length === 0 && emptyObject.constructor === Object;
This returns a truthy value if the given object is empty.
This is however easily achieved with lodash like so:
_.isEmpty({});
Share on social media
//