-1

I wrote the below code to replace all }, with ; but only the first ocurance is getting replaced ,other all remains same..

data1 = "latitude:1.9,longitude:103.57},latitude:1.338,longitude:103.1},latitude:1.33,longitude:103.7556}"
var re = '},'
data = data1.replace(re,';')

I am getting the output like

"latitude:1.9,longitude:103.57;latitude:1.338,longitude:103.1},latitude:1.33,longitude:103.7556}"

expected output

"latitude:1.9,longitude:103.57;latitude:1.338,longitude:103.1;latitude:1.33,longitude:103.7556}"
learnNcode
  • 149
  • 2
  • 4
  • 16

1 Answers1

0

Try this - using a regex to do a global search

data1 = "latitude:1.9,longitude:103.57},latitude:1.338,longitude:103.1},latitude:1.33,longitude:103.7556}"
var re = /},/g
data1.replace(re, ';')

Should return

latitude:1.9,longitude:103.57;latitude:1.338,longitude:103.1;latitude:1.33,longitude:103.7556}
Zahiar
  • 244
  • 1
  • 5
  • 9