JavaScript object literal length === undefined?

Olical picture Olical · Jan 14, 2011 · Viewed 48.4k times · Source

I am working on this animation function but I have a problem. I can't seem to perform what should be an easy task, I can not get the length of an object. If you check out that jsFiddle you can see that I am running alert(properties.length); and it is returning undefined. Can anyone see why this might be?

Answer

Jamund Ferguson picture Jamund Ferguson · Mar 6, 2012

This is supported in node.js and newer environments.

var obj = {a: "a", b: "b"};
Object.keys(obj).length // 2