Iterate through properties of an object I need to round numeric values for properties of a given object.
The following code works fine, but I am concerned if there is a way to make it faster.

I am targeting latest Chrome and Firefox.

http://jsbin.com/bahedegoni/edit?html,output

window.app = {
            start: function () {
                var cmd = {
                    a: 11.12,
                    b: 0.29,
                    c: 'x',
                    d: 'y'
                };
                Object.keys(cmd).forEach(function (prop) {
                    if (typeof cmd[prop] === 'number') {
                        cmd[prop] = Math.round(cmd[prop]);
                    }

                }.bind(this));
                console.log(cmd);
            }
        };
There's no reason to use bind; you don't rely on this anywhere in the code, so it doesn't matter what the this-context is.

Secondly, the "original" way to iterate objects in JavaScript is to use a for...in loop. However, it will also iterate inherited properties, so it's good practice to check if the key's the object's own key by using hasOwnProperty. The basic construction looks like so:

var key;
for(key in object) {
  if(!obj.hasOwnProperty(key)) continue; // skip inherited properties
  // ... do something
}


Thirdly, due to the way JavaScript expresses a NaN (Not A Number) value, it turns out that typeof NaN === 'number'. Of course, it doesn't really matter here since Math.round(NaN) is still NaN.

Point is, this would probably be one of the simplest implementations:

var key;
for(key in cmd) {
  if(obj.hasOwnProperty(key) &amp;&amp; typeof cmd[key] === 'number') {
    cmd[key] = Math.round(cmd[key]);
  }
}