0

Can someone tell me why this is not working, and the variable still holds the string with the ":" in it?

btn_id_postfix = "hehe:haha";
btn_id_postfix.replace(/\:/g,"");
aDvo
  • 894
  • 4
  • 15
  • 43

3 Answers3

0
btn_id_postfix=btn_id_postfix.replace(/\:/g,"");

replace returns value, but doesn't change string.

nicael
  • 18,550
  • 13
  • 57
  • 90
0

replace doesn't change the value of the string you're modifying. What you have to do is simply to assign it to the variable.

btn_id_postfix = "hehe:haha";
btn_id_postfix = btn_id_postfix.replace(/\:/g,"");
cookie monster
  • 10,671
  • 4
  • 31
  • 45
0

You're not assigning the result to a variable. Try this:

btn_id_postfix = "hehe:haha";
btn_id_postfix = btn_id_postfix.replace(/\:/g,"");
CoolBots
  • 4,770
  • 2
  • 16
  • 30