Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 18155

How to replace all occurrences of a string except the first one in JavaScript?

$
0
0

I have this string:

hello world hello world hello world hello

and I need to get the following:

hello world hello hello hello

If I use:

str = str.replace('world', '');

it only removes the first occurrence of world in the above string.

How can I replace all the occurrences of it except the first one?


Viewing all articles
Browse latest Browse all 18155

Trending Articles