View Full Version : Counting Object Properties?

05-04-2007, 02:22 PM
Hi there.
Let's say I get a user-custom JavaScript object, with an unknown number of properties, all of them having custom, unknown names:

var object = {
'foo': 1,
'bar': 2,
'baz': n

Now, let's say I would like to count the number of properties I have inside the object - can I do it? And if so, how?

Plus, can I find out in some way what are the names of the properties, so I could use them?

05-04-2007, 06:12 PM
for (var i in object){
alert(i + "=" + object[i]);