How can I iterate through an Object.Keys(obj) where the obj might change (and thus need to be a variable that changes)?
const modelBasicSKUs = {
device: {
"black": "12",
"platinum": "23"
},
keyboard: {
"black":"12",
"blue":"23",
"red":"34",
"platinum":"45"
},
pen: {
"black":"12",
"platinum":"44",
"burgundy":"56",
"blue":"45"
}
};
(async () => {
let selectedDevice = "modelBasic";
document.querySelector('#testel').innerHTML = tmpl;
const tmpl = `
${Object.keys(selectedDevice + 'SKUs').map(key => (
`<div>${key}</div>`
)).join("")}
`;
})();
<div id="testel"></div>
I believe the important part lies in
${Object.keys(selectedDevice + 'SKUs').map(key => (
Do I need another template literal to be able to point to the other objects when selectedDevice changes? I am guessing that [selectedDevice + 'SKUs] expression returns a string and thus Object.keys does not detect an object out of a string?