You need to sign in to do that
Don't have an account?

How to replace all occurances of any character in javascript.
Hi All,
I am trying to replace all occurances of a perticular string in javascript ,but the value is not getting change
Ex
Var str = 'Hello_world_congrats';
str = str.replace(/_/g,'&');
In this code i am trying to convert all '_' characters with '&' but the value is not getting change.
Can any one please let me know what's wrong in this.
Thanks in advance.
Raj.
HI,
the below line is correct:
str = str.replace(/_/g,'&'); // there is no mistake.
The real mistake is, u need to write 'Var' as var.because 'JavaScript is case sensitive'.
So u need to change the capital V to small v.
var str = 'Hello_world_congrats';
str = str.replace(/_/g,'&');
Please let me know if u have any problem in same and if this post helps u please throw KUDOS by click on star at left.