title: Javascript - easy way to split/devide string by pattern into N parts where last part is rest of the string
body: <p>If i have the strings:</p>
  
  <pre><code>string1 = "1 secondpart this is the third part"
  string2 = "14   secondpartagain   third part   again"
  </code></pre>
  
  <p>and i want to split them by a pattern (like whitespace) into N parts (like 3 parts), then the result should be something like:</p>
  
  <pre><code>part1: "1", part2: "secondpart", part3: "this is the third part"
    -and
  part1: "14", part2: "secondpartagain", part3: "third part   again"
  </code></pre>
  
  <p>In Ruby i would do something like:</p>
  
  <pre><code>part1, part2, part3= string1.split(/\s+/, 3)
  </code></pre>
  
  <p>If i use the split function in Javascript i get something like this:</p>
  
  <pre><code>var myArray1 = string1.split(/\s+/, 3);
  var myArray2 = string2.split(/\s+/, 3);
  
  myArray1[0]: "1", myArray1[1]: "secondpart", myArray1[2]: "this"
    -and
  myArray2[0]: "14", myArray2[1]: "secondpartagain", myArray2[2]: "third"
  </code></pre>
  
  <p>What is the easiest way to split a string by a pattern into N parts where last part is rest of the string?</p>