title: Add a new line in String at nearest space every 100 characters
body: <p>I am coding the back end of a production system for my gelato manufacturing company and I haven't work with Javascript since Freshman year of college. Basically, myString is a list of ingredients in a Google Sheet that is imported from our ordering system. It is usually very long and needs to be split for the label software. I need all of myString to stay in one cell, but have a new line (or CTRL enter) every 100 characters, but it has to be at a space. Here is what I have but it does not work past the first occurrence. </p>
  
  <pre><code>function insertNewLine(myString) {
      var ret = [];
      var i;
      var len;
      var n = 100;
      var currentString = myString.substr(i,n);
      var character = String.fromCharCode(10);
  
      for(i = 0, len = myString.length; i &lt; len; i += 100) {
  
      var before = currentString.lastIndexOf(' ', n);
            n = before;
  
        ret.push(currentString + character);
        currentString = myString.substr(n, n+100);
        n=100;      
      }
  
      return ret;
  }
  </code></pre>
  
  <p>Thanks for any help.</p>