title: Splitting a string based on max character length, but keep words into account
body: <p>So In my program I can receive strings of all kinds of lengths and send them on their way to get translated. If those strings are of a certain character length I receive an error, so I want to check &amp; split those strings if necessary before that. BUT I can't just split the string in the middle of a word, the words themself also need to be intact &amp; taken into account.</p>
  
  <p>So for example:</p>
  
  <pre><code>let str = "this is an input example of one sentence that contains a bit of words and must be split"
  let splitStringArr = [];
  
  // If string is larger than X (for testing make it 20) characters
  if(str.length &gt; 20) {
      // Split string sentence into smaller strings, keep words intact
      //...
      // example of result would be
      // splitStringArr = ['this is an input', 'example of one sentence' 'that contains...', '...']
      // instead of ['this is an input exa' 'mple of one senten' 'ce that contains...']
  }
  </code></pre>
  
  <p>But I'm not sure how to split a sentence and still keep into account the sentence length.</p>
  
  <p>Would a solution for this be to iterate over the string, add every word to it and check every time if it is over the maximum length, otherwise start a new array index, or are there better/existing methods for this?</p>