Possible Duplicate:
Why does javascript replace only first instance when using replace?
I have this variable
var newRow = "<td><div> [[myvar]]</div> <div> [[myvar]]</div> </td> "
When i do this
newRow = newRow.replace('[[myvar]]', '10');
Only first occurance gets replaced and not the second
You might use a regular expression
newRow = newRow.replace(/\[\[myvar\]\]/g, '10');
There is no other simple solution for multiple replacements. Note that :
/\[\[myvar\]\]/ notationnew RegExp(somepattern, 'g') (but for better performances don't use this if you have a fixed pattern)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With