I have this scenario where I get a string that might contain variables which are meant to be replaced with values from a json object
string = "Please input your %info1% in the %screen1% dialog and specify your %info2%. Thank you"
json = {
info1: "name",
info2: "age",
screen1: "information"
}
I want to know if there is a way to avoid passing this to a function that should first check how many variables the string has (there are many strings to manipulate, which could have from 1 to 5 variables) using loops and stuff, and instead doing something like (will type it kind of pseudocode):
string.forEach(variable => replace variable with value from json)
return resulting string
Thanks!