How to replace all occurrences of character in a string in Node.js

3 Answers

0 votes
let s = "node.js php c++ PHP css python";
    
s = s.replace(/p/g, "*");
 
console.log(s);
  
   
   
    
    
/*
run:
    
node.js *h* c++ PHP css *ython
   
*/

 



answered Jan 23, 2022 by avibootz
0 votes
let s = "node.js php c++ PHP css python";
    
s = s.split('p').join('*');
 
console.log(s);

   
    
    
/*
run:
    
node.js *h* c++ PHP css *ython
   
*/

 



answered Jan 23, 2022 by avibootz
0 votes
let s = "node.js php c++ PHP css python";
     
s = s.replace(/p/gi, "*");
  
console.log(s);
   
    
    
     
     
/*
run:
     
node.js *h* c++ *H* css *ython
    
*/

 



answered Jan 23, 2022 by avibootz
...