How to check if object has any properties in JavaScript?

后端 未结 16 2348
自闭症患者
自闭症患者 2020-12-04 08:10

Assuming I declare

var ad = {}; 

How can I check whether this object will contain any user-defined properties?

16条回答
  •  鱼传尺愫
    2020-12-04 08:56

    If you are willing to use lodash, you can use the some method.

    _.some(obj) // returns true or false
    

    See this small jsbin example

提交回复
热议问题