Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In ECMAScript 5 you have new approach in iteration fields of literal - <code>Object.keys</code></p> <p>More information you can see on <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys" rel="noreferrer">MDN</a></p> <p>My choice is below as a faster solution in current versions of browsers (Chrome30, IE10, FF25)</p> <pre><code>var keys = Object.keys(p), len = keys.length, i = 0, prop, value; while (i &lt; len) { prop = keys[i]; value = p[prop]; i += 1; } </code></pre> <p>You can compare performance of this approach with different implementations on <a href="http://jsperf.com/" rel="noreferrer">jsperf.com</a>:</p> <ul> <li><a href="http://jsperf.com/extendimplementations/2" rel="noreferrer">Extend Implementations</a></li> <li><a href="http://jsperf.com/object-keys-iteration/30" rel="noreferrer">Object keys iteration</a></li> <li><a href="http://jsperf.com/object-literal-iteration/5" rel="noreferrer">object literal iteration</a></li> </ul> <p>Browser support you can see on <a href="http://kangax.github.io/es5-compat-table/#Object.keys" rel="noreferrer">Kangax's compat table</a></p> <p>For old browser you have <a href="http://tokenposts.blogspot.com.au/2012/04/javascript-objectkeys-browser.html" rel="noreferrer">simple</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys" rel="noreferrer">full</a> polyfill</p> <p><strong>UPD:</strong></p> <p>performance comparison for all most popular cases in this question on <code>perfjs.info</code>:</p> <p><a href="http://perfjs.info/#!/384A61CA-DA2E-4FD2-A113-080010D4A42B" rel="noreferrer">object literal iteration</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload