Lodash: object check is empty

I have this object: {"": undefined}

and when I check this object is empty: _.isEmpty({"": undefined})

I get the result false, maybe there is another method in lodash?

+4
source share
3 answers

Your sample object is not empty, so instead you want to check if all the properties are undefined

let o = {foo: undefined};
!_.values(o).some(x => x !== undefined); // true
+8
source
_.isEmpty(obj, true)

var obj = {
  'firstName': undefined
, 'lastName' : undefined
};

console.log(_.isEmpty(obj)); // false
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>
Run codeHide result

Please see http://www.ericfeminella.com/blog/2012/08/18/determining-if-an-object-is-empty-with-underscore-lo-dash/

+5
source

, . some every

:

import { some, isEmpty } from 'lodash'
console.log(some(this.yourObject, isEmpty))
0

All Articles