original string is "a,d,k"
I want to remove all , and make it to "adk".
I tried code below but it doesn’t work.
"a,d,k".replace(/,/,"")
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You aren’t assigning the result of the replace method back to your variable. When you call replace, it returns a new string without modifying the old one.
For example, load this into your favorite browser:
In this case,
str1will still be"a,d,k"andstr2will be"adk".If you want to change
str1, you should be doing: