How to convert a word in a string to uppercase in Node.js

2 Answers

0 votes
let str = "The Worlds most reliable Programming Q&A website worlds";
  
str = str.replace(/worlds/gi, function UpperCase(s) { return s.toUpperCase(); });
   
console.log(str);
 
 
 
                    
/*
run:
  
The WORLDS most reliable Programming Q&A website WORLDS
   
*/

 



answered May 22, 2022 by avibootz
0 votes
let str = "The Worlds most reliable Programming Q&A website worlds";
  
const the_word = "Worlds";

const re = new RegExp(the_word, "gi");
 
str = str.replace(re, function UpperCase(s) { return s.toUpperCase(); });
   
console.log(str);
 
 
 
                    
/*
run:
  
The WORLDS most reliable Programming Q&A website WORLDS
   
*/

 



answered May 22, 2022 by avibootz

Related questions

2 answers 244 views
1 answer 179 views
2 answers 259 views
1 answer 211 views
...