代码描述:js对象属性个数。js如何获取指定对象中含有属性的个数
在实际应用中可能需哟啊对象中含有属性的个数,下面就通过实例代码简单介绍一下如何实现此功能。 代码实例如下:
<script> Object.prototype.count=( Object.prototype.hasOwnProperty('__count__'))?function(){ return this.__count__; } : function (){ var count = 0; for (var i in this) if (this.hasOwnProperty(i)){ count ++; } return count; }; var antzone={ webName: "51前端", age:2, webAddress:"青岛市南区" }; console.log(antzone.count()); </script>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能