title: JavaScript Array Push Missing Values
body: <p>This function will take an array and chunk it into separate arrays, create an offset at the beginning and wrap that in another array. The problem I have is not all of the numbers from the original array (arr1) are included in the chunks. You can see the output in the link I have provided below. It misses out numbers 5, 13, 21, 29 and 30. Can anyone explain why this happens?</p>
  
  <pre><code>function chunkifyArray(input, chunkSize, offset) {
  
      const output = [];
  
      let tmp = offset ? new Array(offset).fill('') : [];
  
      for(var i = 0; i &lt; input.length; i++){
          if (tmp.length &lt; chunkSize) {
              tmp.push(input[i]);
          } else {
              output.push(tmp);
              tmp = [];     
          }
      }
  
      return output;
  }
  
  var arr1 = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30'];
  console.log(chunkifyArray(arr1, 7, 3));
  </code></pre>
  
  <p><a href="https://jsbin.com/zucaguvoti/edit?js,console" rel="nofollow noreferrer">https://jsbin.com/zucaguvoti/edit?js,console</a></p>