Let me make replaceAll in Javascript

There is no replaceAll in javascript

if you use replace

ex) var orgStr = "welcome to my blog to have a fun";
     orgStr = orgStr.replace('to', 'ha');
     console.log(orgStr);
     output = "welcome ha my blog to have a fun"

It mean only first String will be replaced but otheres not,

So this is good solution

var orgStr = "welcome to my blog to have a fun";
     orgStr = orgStr.split('to').join('ha');
     console.log(orgStr);
     output = "welcome ha my blog ha have a fun"


Comments

Popular posts from this blog

Project euler 169 found clue

Floyd-Warshall's algorithm