Answers for "use replace in javascript"

6

str replace javascript all

str.replace(/abc/g, '');
Posted by: Guest on May-16-2020
10

javascript replace

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"
Posted by: Guest on July-25-2020
6

replace all javascript

str.split(search).join(replacement);
Posted by: Guest on May-01-2020
2

javascript replace

var text = "Sentence with old text"
alert( text.replace("old text", "new text") ); // Sentence with new text
Posted by: Guest on March-14-2021

Code answers related to "use replace in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language