title: Merge every 3 elements in array javascript
body: <p>I'm new to programming, and would appreciate any help.</p>
  <p>Suppose I have the following array. (Note that this array comprises of 6 elements)</p>
  <pre><code>var data = 
  [
    'he' ,
    'l' ,
    'lo',
    'th',
    'e',
    're',
  
  ]
  
  </code></pre>
  <p>My goal here, is  to either to create a new array  that joins every three elements, into a single element.</p>
  <p>Currently, my novice approach to this problem, is to use a simple for loop, to take each element, and add the index of the element +1 and the index of the element + 2 to the initial element.</p>
  <p>The code seems to work partially, but since it iterates through each element and not every 3, it joins the elements too many times.</p>
  <p>Here is my code:</p>
  <pre><code>
  var data = 
  [
    'he' ,
    'l' ,
    'lo',
    'th',
    'e',
    're',
  
  ]
  
  var newdata = []
          for (var i = 0; i &lt; data.length; i++) {
   var three = data[i] + data[i+1] + data[i+2]
   newdata.push(three)
  
  }
  console.log(newdata) // =&gt; This will output  'hello', 'lloth' 'lothe' 'there' 'ereundefined' 'reundefinedundefined'
  </code></pre>
  <p>The desired output is this:</p>
  <pre><code>var data = 
  [
  'hello',
  'there',
  ]
  </code></pre>
  <p>To get this existing code working, I assume I would have to delete the element + element +1 and element + 2, so that it doesn't join things unnecessarily  the correctly, but I've had no success with that.</p>
  <p>I'm open to other solutions/alternates that get the same output.</p>
  <p>Any help is highly appreciated.</p>