I want to use str_replace or its similar alternative to replace some text in JavaScript.
str_replace
var text = \"this is some sample text that i want to re
You would use the replace method:
replace
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.