title: javascript how to add a row every forth cell?
body: <p>i'm creating a table with javascript. i want my table to have 4 cells in one row, so 5th cell would be in new row. </p>
  
  <p>if i have 10 objects to display on the cells, i would have 2 full rows and 1 row with only 2cells. </p>
  
  <p>here's the code that i have. any idea??</p>
  
  <pre><code>var a = { style: ["1","2","3","4", "5","6"]};
  
  var oldTable = document.getElementById('example'),
  newTable = oldTable.cloneNode();
  
  var b = a.style.length;
  for (var i= 0; i &lt;= 4; i++){
      if (b &gt;= 4) {
      var tr = document.createElement('tr');
  
          var k = "";
      for(var j = 0; j &lt; b; j++) {
          var td = document.createElement('td');
          var div = document.createElement('div');
          div.style.width="175px";
          div.style.height="250px";
  
          div.appendChild(document.createTextNode(a.style[k++]));
          td.appendChild(div);
          tr.appendChild(td);
             }
      }
  newTable.appendChild(tr);
  }
  oldTable.parentNode.replaceChild(newTable, oldTable);
  </code></pre>