How to check if object has any properties in JavaScript?

后端 未结 16 2375
自闭症患者
自闭症患者 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 09:07

    Late answer, but some frameworks handle objects as enumerables. Therefore, bob.js can do it like this:

    var objToTest = {};
    var propertyCount = bob.collections.extend(objToTest).count();
    

提交回复
热议问题