HOOO let data = { copy: "hee", hello: "HOOO" } let oop = $("body").text() function yee () { return oop.replace(/\&([^}]+)\;/g, (str, match) => { if (typeof data[match] == "undefined") { return str; } else { return data[match] } }) } $("body").text(yee())