lodash: check object is empty

非 Y 不嫁゛ 提交于 2019-11-30 17:13:31

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
Armen Zakaryan
_.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>

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

It depends on how you want to check it. Do you want to check some or every

Then what you can do is :

import { some, isEmpty } from 'lodash'
console.log(some(this.yourObject, isEmpty))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!