I have this object: {"": undefined}
and when I check this object for empty in this way: _.isEmpty({"": undefined})
I get false
result, maybe in lodash we have another method?
The Lodash _. isEmpty() Method Checks if the value is an empty object, collection, map, or set. Objects are considered empty if they have no own enumerable string keyed properties. Collections are considered empty if they have a 0 length.
isEmpty() function: It is used to check whether a list, array, string, object etc is empty or not.
There are only seven values that are falsy in JavaScript, and empty objects are not one of them.
_.isEmpty(obj, true)
var obj = { 'firstName': undefined , 'lastName' : undefined }; console.log(_.isEmpty(obj)); // false console.log(_.isEmpty({})); // true
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>
Please, see http://www.ericfeminella.com/blog/2012/08/18/determining-if-an-object-is-empty-with-underscore-lo-dash/
Your example object is not empty so instead perhaps you want to test if all properties are undefined
let o = {foo: undefined}; !_.values(o).some(x => x !== undefined); // true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With