Is it possible to interpolate a template string using key/values from a object in JavaScript, like string substitution in Python:
data = {"age": 18, "name": "John"}
"I'm %(name)s. I'm %(age)d years old" % data # "I'm John. I'm 18 years old"
One way that I can think of is using the with statement,
let data = {age: 18, name: "John"}
with(data){`I'm ${name}. I'm ${age} years old`}
but with is highly not recommended, it is neither efficient nor safe.
Is there a better way?
You can destruct data object:
or do this: