Javascript-split() not working when there are repeated chars in a string
<p>Not sure how valid is this approach, but I'm unable to split the string into 2 when there are repeated characters. </p>

<pre><code> var match = 's';
 var str = "message";
 var res = str.split(match, 2);
</code></pre>

<p>For instance i tried to use split() on the string "message", it results into:</p>

<pre><code>me,""
</code></pre>

<p>So i did this:</p>

<pre><code> res = str.split(match, 3);
</code></pre>

<p>so now it resulted into:</p>

<pre><code>me,,age
</code></pre>

<p>but as you can see im still missing the second 's' in the "message" string. what im trying to get is I'm passing a matched character (in above case var match which is dynamically generated) to the split() and splitting into 2. I was hoping to get something this:</p>

<pre><code>res = me,,sage
</code></pre>

<p>is that possible using split() or is there a better method to achieve this?</p>

<p>P.S: in fiddle i've given another string eg: (string = "shadow") which works fine.
Fails only when there are repeated letters in the string!</p>

<p>fiddle: <a href="https://jsfiddle.net/ukeeq656/" rel="nofollow">https://jsfiddle.net/ukeeq656/</a></p>

<p>EDIT::::::::::::</p>

<p>Thanks everyone for helping me out on this...and so sorry for last min update on the input, i just realized that <code>var match;</code> could be a word too, as in <code>var match = 'force';</code> and not just <code>var match ='s';</code> where the string is "forceProduct", so when my match is more than just a letter, this approach works: <code>str.split(match, 2);</code>, but <code>str.indexOf(match);</code> doesnt obviously... could there be an approach to split: "","Product". My extreme apologies for not mentioning this earlier.any help on this would be appreciated!!</p>

<p>eg fiddle:
<a href="https://jsfiddle.net/ukeeq656/3/" rel="nofollow">https://jsfiddle.net/ukeeq656/3/</a></p>