Skip to content
Menu
Justin Ball
  • About
  • Privacy Policy
Justin Ball

Category: global

In javascript string replace doesn’t do what you think it does

Posted on January 20, 2011October 25, 2021

When doing a string replace in javascript if you try something like this: var str = ‘test’; str.replace(‘t’, ‘s’); You’ll find that the result is: sest The replace method in javascript is not a global replace. Instead it does a single replace and moves on. If you want to do a global replace try using…

©2025 Justin Ball | Powered by SuperbThemes & WordPress