The first ( for ( in ) ) reads the property names from the object.
So you can read it as for every property in myObj , assign it x .
The second ( for each ( in ) ) reads the property values โโof the object.
This can be read as for each property value in myObj , assign it x .
Please note that for each has limited browser support.
Also note that if additional properties appear in for ( in ) , this is due to the fact that he will look for a prototype chain for additional enumerated properties (for example, someone may have Object added).
You can reduce this with ...
for (var x in myObj) { if ( ! myObj.hasOwnProperty(x)) { continue; }
jsFiddle .
source share