Answers for "replace with in javascript"

31

javascript replace

var res = str.replace("find", "replace");
Posted by: Guest on October-21-2019
9

how to use the replace method in javascript

let string = 'soandso, my name is soandso';

let replaced = string.replace(/soandso/gi, 'Dylan');

console.log(replaced); //Dylan, my name is Dylan
Posted by: Guest on April-15-2020
4

javascript replace

// Valor retornado: “Aprendendo JavaScript. JavaScript é na DevMedia”
exemplo = "Aprendendo Javascript. JAVAScript é na DevMedia ";
resultado = exemplo.replace(/javascript/gi, "JavaScript");
Posted by: Guest on February-16-2021
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
5

javascript string replace

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"
Posted by: Guest on May-22-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 "replace with in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language