Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A slightly convoluted means of achieving your end-result:</p> <pre><code>// splits the supplied string by the hyphen '-' character var string = 'comment-f78d0b00-a008-473d-b647-a4a103ee3778'.split(/-/); // removes the zeroeth/first element from the string array string.shift(); // joins the remaining elements from the string back together var newString = string.join('-'); console.log(newString);​ </code></pre> <p><a href="http://jsfiddle.net/davidThomas/uWCgg/1/" rel="nofollow">JS Fiddle demo</a>.</p> <hr /> <p><strong>Edited</strong> to turn the above into a function:</p> <pre><code>function splitString(haystack, needle){ if (!needle || !haystack){ return false; } var string = haystack.split(needle); string.shift(); return string.join(needle); } // the first argument is the string you want to work on, // the second is the character you want to split on // f is the variable that will hold the new string var f = splitString('comment-f78d0b00-a008-473d-b647-a4a103ee3778','-'); console.log(f);​ </code></pre> <p><a href="http://jsfiddle.net/davidThomas/uWCgg/2/" rel="nofollow">JS Fiddle demo</a>.</p> <p>References:</p> <ul> <li><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/join" rel="nofollow"><code>join()</code></a>.</li> <li><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/shift" rel="nofollow"><code>shift()</code></a>.</li> <li><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split" rel="nofollow"><code>split()</code></a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload