Answers for "js replace characters in string"

7

replacing characters in string javascript

var myStr = 'this,is,a,test';
var newStr = myStr.replace(/,/g, '-');

console.log( newStr );  // "this-is-a-test"
Posted by: Guest on October-20-2020
6

js replace characters in a string

var str = "Original string!";
var str = str.replace("Original", "New");
Posted by: Guest on September-29-2020
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

Code answers related to "js replace characters in string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language