I have a JavaScript object. Is there a built-in or accepted best practice way to get the length of this object?
const myObject = new Object(); myObject["
A variation on some of the above is:
var objLength = function(obj){ var key,len=0; for(key in obj){ len += Number( obj.hasOwnProperty(key) ); } return len; };
It is a bit more elegant way to integrate hasOwnProp.