How to replace all occurrences in javascript

To replace all occurrences in a string use the “g” modifier without double quote like this

var strvar = “one two one”;

strvar = strvar.replace(/one/g,”1″);

the output of the strvar would be “1 two 1″

,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth