Determining if all attributes on a javascript object are null or an empty string

后端 未结 15 1800
走了就别回头了
走了就别回头了 2020-12-08 04:08

What is the most elegant way to determine if all attributes in a javascript object are either null or the empty string? It should work for an arbitrary number of attributes

15条回答
  •  自闭症患者
    2020-12-08 04:38

    Building on top of other answers I would use lodash to check isEmpty on the object, as well as its properties.

    const isEmpty = (object) => return _.isEmpty(object) || !Object.values(object).some(x => !_.isEmpty(x))
    

提交回复
热议问题