This content originally appeared on CodeSource.io and was authored 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({});
The post Testing for an empty object in Javascript appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Prince Chukwudire

Prince Chukwudire | Sciencx (2021-02-18T17:17:19+00:00) Testing for an empty object in Javascript. Retrieved from https://www.scien.cx/2021/02/18/testing-for-an-empty-object-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.