I want to use str_replace or its similar alternative to replace some text in JavaScript.
var text = \"this is some sample text that i want to re
If you don't want to use regex then you can use this function which will replace all in a string
function ReplaceAll(mystring, search_word, replace_with)
{
while (mystring.includes(search_word))
{
mystring = mystring.replace(search_word, replace_with);
}
return mystring;
}
var mystring = ReplaceAll("Test Test", "Test", "Hello");