How can I perform a str_replace in JavaScript, replacing text in JavaScript?

You would use the replace method:

text = text.replace('old', 'new');

The first argument is what you’re looking for, obviously. It can also accept regular expressions.

Just remember that it does not change the original string. It only returns the new value.

Leave a Comment