Answers for "how to replace value in javascript"

31

javascript replace

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

replace element from string javascript

var string="hollo"
console.log(string.replace(/o/g,'P'))
//replace o with P
Posted by: Guest on May-31-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
1

javascript replace

var frase = "Son tres mil trescientos treinta y tres con nueve";
frase = frase.replace("tres","dos");
console.log(frase);
//Son dos mil trescientos treinta y tres con nueve
Posted by: Guest on November-16-2020

Code answers related to "how to replace value in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language