performance - How to efficiently count the number of keys/properties of an object in JavaScript? -


what's fastest way count number of keys/properties of object? it possible without iterating on object? i.e. without doing

var count = 0; (k in myobj) if (myobj.hasownproperty(k)) count++; 

(firefox did provide magic __count__ property, removed somewhere around version 4.)

to in es5-compatible environment, such node, chrome, ie 9+, ff 4+, or safari 5+:

object.keys(obj).length 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -