-1

I want to Replace 2013-2-2 to 2013,2,2

I tried

var forrep = '2013-2-2'; 

var text = forrep.replace('-', ',');

but it only replaces the first - the output looks like this 2013,2-2

I want all the - to be replaced by , commna

Please help Thanks

user229044
  • 232,980
  • 40
  • 330
  • 338
Bongsky
  • 493
  • 3
  • 12
  • 23
  • 1
    possible duplicate of [Javascript multiple replace](http://stackoverflow.com/questions/832257/javascript-multiple-replace) – user229044 Jan 14 '14 at 03:25

1 Answers1

5

Use a regular expression with the /g switch to make it match "globally":

var text = forrep.replace(/-/g, ',');
user229044
  • 232,980
  • 40
  • 330
  • 338