replace text javascript
xxxxxxxxxx
document.querySelector('.footer-column--appointments .et_pb_text_inner h3')
.innerHTML =
document.querySelector('.footer-column--appointments .et_pb_text_inner h3')
.innerHTML.replace('Set','Appointment');
replace text javascript
xxxxxxxxxx
var str = "JavaScript replace method test";
var res = str.replace("test", "success");
//res = Javscript replace method success
xxxxxxxxxx
var string = "golden vigor doers goat";
var replacedString = string.replace("go", "GO");
console.log(replacedString);
xxxxxxxxxx
let text = "I love you"
text = text.replace( / +/g, '_') // replace with underscore ('_')
console.log(text) // I_love_you
xxxxxxxxxx
const p = 'dog dog cat rat';
const regex = /dog/gi;
console.log(p.replace(regex, 'cow'));
//if pattern is regular expression all matches will be replaced
//output: "cow cow cat rat"
console.log(p.replace('dog', 'cow'));
// If pattern is a string, only the first occurrence will be replaced.
//output: "cow dog cat rat"
xxxxxxxxxx
var str = "Please locate where 'locate' occurs!";
str.replace("locate", "W3Schools"); //replace only replace first match from string
str.replace(/LOCATE/i, "W3Schools"); // i makes it case insensitive
str.replace(/LOCATE/g, "W3Schools"); // g replace all matches from string rather than replacing only first
xxxxxxxxxx
const p = 'Its going to rain today and its going to rain tomorrow';
// Example of replacing all occurrances
// g = global search, which searches all instances
// i = case insensitive, which will match 'a' with 'A'
const regex = /rain/gi;
console.log(p.replace(regex, 'snow'));
// expected output: "Its going to snow today and its going to snow tomorrow"
// Example of replacing the first occurance
console.log(p.replace('rain', 'snow'));
// expected output: "Its going to snow today and its going to rain tomorrow"
xxxxxxxxxx
var string = "Javascript is fun";
var newString = string.replace("fun", "Awesome");
console.log(newString); // Javascript is Awesome
xxxxxxxxxx
you need to be very carefull to use 'MyStringggg'.replaceAll('rep','toRep')
for those coming from c# or java or ...
because replace just replcaes the first occurance but if you want replace all occurances then you need to use replaceAll