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
  • 862
  • 3
  • 15
  • 41

3 Answers3

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

replace returns value, but doesn't change string.

nicael
  • 17,612
  • 12
  • 55
  • 87
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,261
  • 3
  • 30
  • 44
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,587
  • 2
  • 14
  • 27