javascript - Fastest method to replace all instances of a character in a string -
    What is the fastest way to change all the examples of  string / character  in a string  Javascript ? A  while , a  for-loop , a  regular expression ?     To change all instances, it would be easy to use a regular expression with the  g  flag:    str.replace / foo / g, "bar")    with  foo  with  bar  string  str If you have just one string, you can change it to a RegExp object:    var pattern = "foobar", then = new RegExp (pattern, "g ");