DEV Community

Discussion on: How to Check if Object is Empty in JavaScript

Collapse
 
functional_js profile image
Functional Javascript

I've only used my isEmptyObj in sanitization code.
Cleaning out empty values from incoming data.

Collapse
 
pentacular profile image
pentacular

Hmm, I still can't figure out why you'd ever want to do that.

Surely you want to check the object for having some set of required and forbidden properties.

Checking for an empty object seems completely useless, because if you wanted an empty object you could just make one yourself.

And if you didn't want an empty object, that means that you want some object with some properties, in which case you can check for the properties that you want.

So, I still can't figure out why you'd ever want to check if an object is empty.