title: Limiting the times that .split() splits, rather than truncating the resulting array
body: <p>Really, pretty much what the title says.</p>
  
  <p>Say you have this string:</p>
  
  <pre><code>var theString = "a=b=c=d";
  </code></pre>
  
  
  
  <p>Now, when you run <code>theString.split("=")</code> the result is <code>["a", "b", "c", "d"]</code> as expected. And, of course, when you run <code>theString.split("=", 2)</code> you get <code>["a", "b"]</code>, which after reading <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split" rel="noreferrer">the MDN page for <code>String#split()</code></a> makes sense to me.</p>
  
  <p>However, the behavior I'm looking for is more like Java's <code>String#split()</code>: Instead of building the array normally, then returning the first <em>n</em> elements, it builds an array of the first <em>n-1</em> matches, then adds all the remaining characters as the last element of the array. See <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#split-java.lang.String-int-" rel="noreferrer">the relevant docs</a> for a better description.</p>
  
  <p>How can I get this effect in Javascript?</p>
  
  <p>I'm looking for the answer with the best performance that works like the Java implementation, though the actual way it works can be different. </p>
  
  <p>I'd post my attempt, but I don't know how to go about writing this at all.</p>