I am trying to find a way to map data from an object into a string template using JavaScript. Here is an example of the string and object I am working with:
const menu = {
breakfast: {
description:'something'
}
meal: {
description: 'anotherSomething'
}
}
const template = `<div>
<ul>
<li>
%breakfast.description%
</li>
<li>
%meal.description%
</li>
</ul>
</div>
`
Instead of creating arrays and looping through keys, I am looking for a more elegant solution where I can dynamically access the object directly within the string like in a template literal. Any suggestions or solutions would be greatly appreciated!