title: Splitting an array up into chunks of a given size
body: <p>I have written a function which takes two parameters: (1) an Array, (2) size of the chunk.</p>
  
  <pre><code>function chunkArrayInGroups(arr, size) {
  
    var myArray = [];
  
    for(var i = 0; i &lt; arr.length; i += size) {
      myArray.push(arr.slice(i,size));
    }
  
    return myArray;
  }
  </code></pre>
  
  <p>I want to split this array up into chunks of the given size.</p>
  
  <pre><code>chunkArrayInGroups(["a", "b", "c", "d"], 2)  
  </code></pre>
  
  <p>should return: <code>[["a", "b"], ["c", "d"]]</code>.</p>
  
  <p>I get back: <code>[["a", "b"], []]</code> </p>