How to replace text in string in JavaScript

2 Answers

0 votes
var s1 = "The worlds most popular Programming Q&A";

s1 = s1.replace("Programming", "Code");
 
document.write(s1);

                  
/*
run:

The worlds most popular Code Q&A 
 
*/

 



answered Jun 10, 2015 by avibootz
0 votes
var s1 = "The worlds most reliable Programming Q&A worlds";

s1 = s1.replace("worlds", "cosmos");
 
document.write(s1);

                  
/*
run:

The cosmos most reliable Programming Q&A worlds 
 
*/

 



answered Jun 10, 2015 by avibootz
...