I need get js object properties count.
I search and found solutions like this:
var foo = {"key1": "value1", "key2": "value2", "key3": "value3"};
var count = 0;
for (var k in foo) {
if (foo.hasOwnProperty(k)) {
++count;
}
}
Question: why needed condition if (foo.hasOwnProperty(k)) {
?
I think that this code must work good always, without this condition also.
I am wrong?