I made this code trying to reproduce what i want to do in my Node JS API. I have "message" Array and "valueList" Object and i need to replace all text with "@" than have name of variables in "valueList" Object.
const message = [
"Hi my name is @myname from @city",
"Hi i'm a bot @botname from @city"
]
const valueList = {
myname: "Roger",
city: "Rio",
botname: "Re"
}
/** This is my trying */
const replacedText = message
.map((text) => text.replace("@myname",valueList.myname))
.map((text) => text.replace("@botname",valueList.botname))
.map((text) => text.replace("@city",valueList.city))
console.log(replacedText)
If i create one more variable in valueList i need to put one more .map in message, is possible to get automatically all object to replace all "message" ? i'm trying to do that, Thanks.