Answers for "change string javascript"

31

javascript replace

var res = str.replace("find", "replace");
Posted by: Guest on October-21-2019
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
0

how to change a sting into js code

eval('you code here')
Posted by: Guest on March-09-2021

Code answers related to "change string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language