title: Split a JavaScript string into fixed-length pieces
body: <p>I would like to split a string into fixed-length (<em>N</em>, for example) pieces. Of course, last piece could be shorter, if original string's length is not multiple of <em>N</em>.</p>
  
  <p>I need the fastest method to do it, but also the simplest to write. The way I have been doing it until now is the following:</p>
  
  <pre><code>var a = 'aaaabbbbccccee';
  var b = [];
  for(var i = 4; i &lt; a.length; i += 4){ // length 4, for example
      b.push(a.slice(i-4, i));
  }
  b.push(a.slice(a.length - (4 - a.length % 4))); // last fragment
  </code></pre>
  
  <p>I think there must be a better way to do what I want. But I don't want extra modules or libraries, just simple JavaScript if it's possible.</p>
  
  <p>Before ask, I have seen some solutions to resolve this problem using other languages, but they are not designed with JavaScript in mind.</p>