Javascript Data Type How to - Cut a string at nth occurrence of a character








Question

We would like to know how to cut a string at nth occurrence of a character.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from   www.  java 2  s .  c o  m-->
var str = 'this.those.that',
    delimiter = '.',
    start = 1,
    tokens = str.split(delimiter).slice(start),
    result = tokens.join(delimiter);
document.body.innerHTML = result;

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: