开发者

How do I know how many items an object literal contains?

开发者 https://www.devze.com 2022-12-17 02:58 出处:网络
For example, how do I know that the myObject object liter开发者_如何学编程al contains two items?

For example, how do I know that the myObject object liter开发者_如何学编程al contains two items?

var myObject = {
  item1 : "blablabla",
  item2 : "blablabla
};


How do I count a JavaScript object's attributes?


var n = 0
for (var i in o) ++n
alert(n)


If you didn't override the prototypes of myObject,

var count = 0;
for (var k in myObject) ++ count;
return count;

Otherwise, see the answer haim's link.

0

精彩评论

暂无评论...
验证码 换一张
取 消