I have a weather API that feeds current info in written as "AmericaNew_York" and want to add spaces and remove the underscore to look better, how could you do that in JavaScript?

Table of Contents

America/New_York

You can use the u2018String.

prototype.

replaceu2019 function.

Want to replace that underscore with a space? Easy! Just do this:,u2018America/New_Yorku2019.

replace(u2018_u2019, u2018 u2018),the first argument is what you want to replace and the 2nd one is what you want to replace it with.

You can also chain multiple replace functions, so that if you wanted to also replace u2018/u2018 with a space, you could do this:,u2018America/New_Yorku2019.

replace(u2018_u2019, u2018 u2018).

replace(u2018/u2018, u2018 u2018),or you can do it in a single invocation if you use a regular expression pattern to target both u2018/u2018 and u2018_u2019.