JSFiddle - React, Tailwind, and code Playground
HTML
<button onclick="replaceText('tokenX replaced: {tokenX}')">Try it</button>
<p id="demo"></p>
<script>
var replacementText = {
"tokenX": "tokenXReplaced",
"tokenY": "tokenYReplaced",
"tokenZ": "tokenZReplaced"
};
function replaceText(text) {
for(var rt in replacementText) {
text = text.replace(new RegExp("{" + rt + "}"), replacementText[rt]);
}
document.getElementById("demo").innerHTML = text;
}
</script>