I have below string.
const msg='this is the ${sentence} to end all ${sentence}'
I want to replace all occurances of ${sentence} by 'message'.
When I am doing
var newMsg = msg.replace('${sentence}', 'message')
It gives output-
this is the message to end all ${sentence}
But I want to replace all occurances of ${sentence}
. So I tried
var newMsg = msg.replace(/${sentence}/g, 'message')
And what if I want to replace all occurance of dynamic String.
var str = JSON.stringify(JsonData).toString();
for (let [key, value] of Object.entries(dummyData)) {
str = str.replace('${'+key+'}', value)
}
Here JsonData is the JSON file whoes values I want to replace with values from dummyData(which is an object) Please suggest how can I achieve this. Thanks in advance.