方法一: var obj = {p:1;c:2} var arr = Object.keys(obj); arr.length;code
var obj = {p:1;c:2} var arr = Object.keys(obj); arr.length;
方法二: function getPropertyCount(o){ var n, count = 0; for (n in obj) { if(o.hasOwnProperty(n)){ count++; } } return count; }get
function getPropertyCount(o){ var n, count = 0; for (n in obj) { if(o.hasOwnProperty(n)){ count++; } } return count; }