How do I replace the'-'in a date with'/'?

for example, date = "2018-11-23"
I wrote var date = date.replace ("-", "/")
printed out the result is 2018 code 11-23 .

Dec.08,2021

needs to add g to indicate the global, otherwise it will only match to the first

.
var date = date.replace(/-/g, "/");

the preceding matching parameters are regular /-/ g


clipboard.png

Menu