title: how to show only x number of divisions using JavaScript and the for loop
body: <p>I use below script to show dynamic data in a descending order:</p>
  
  <pre><code>var main = document.getElementById( 'container' );
  
  [].map.call( main.children, Object ).sort( function ( a, b ) {
      return +b.id.match( /\d+/ ) - +a.id.match( /\d+/ );
  }).forEach( function ( elem ) {
      main.appendChild( elem );
      }
  
  });
  </code></pre>
  
  <p>With PHP, it shows the following for instance:</p>
  
  <pre><code>&lt;div id="container"&gt;
    &lt;div id="data-7"&gt;data 7&lt;/div&gt;
    &lt;div id="data-6"&gt;data 6&lt;/div&gt;
    &lt;div id="data-5"&gt;data 5&lt;/div&gt;
    &lt;div id="data-4"&gt;data 4&lt;/div&gt;
    &lt;div id="data-3"&gt;data 3&lt;/div&gt;
    &lt;div id="data-2"&gt;data 2&lt;/div&gt;
    &lt;div id="data-1"&gt;data 1&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I want to show only 5 divisions inside <code>&lt;div id="container"&gt;</code> so I tried adding this in the <code>forEeach</code> but it didn't work :</p>
  
  <pre><code>for (i = 0; i &lt; 5; i++) {
  }
  </code></pre>
  
  <p>Any thoughts ?</p>