nana
nana

Reputation: 11

how replace a character in a string in javascript

i have a string :

var s="here_we_go";

how can i replace all occurrence of '_' by '$' so the string will become:

s="here$we$go";

Upvotes: 1

Views: 2061

Answers (1)

kennytm
kennytm

Reputation: 523154

Use .replace....

s.replace(/_/g, '$');

The g here ensures every (not just one) occurrences of _ will be replaced by $.

Upvotes: 7

Related Questions