开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜