开发者

.replace() not working correctly

开发者 https://www.devze.com 2023-02-02 08:57 出处:网络
I have a string that i would like to convert. the string is image and the content is: Gone in 60 seconds

I have a string that i would like to convert.

the string is image and the content is: Gone in 60 seconds What i need is the following: Gone_in_60_seconds But when i try: image = image.replace(" ","_"); the result is: 开发者_如何学JAVAGone_in 60 seconds so only the first space gets replaced. How would i convert all the spaces to underscores?


Try this:

image = image.replace(/ /g, "_");
0

精彩评论

暂无评论...
验证码 换一张
取 消