I have an Object of Arrays with a key to identify each Array. I would like to make a render function, which can append the key's names to an unordered list in my HTML document, and append a new unordered list for each key, with a list of each value for that key.
Example
<ul>
<li>Key1</li>
<ul>
<li>Value1</li>
<li>Value2</li>
</ul>
<li>Key2</li>
<ul>
<li>Value1</li>
<li>Value2</li>
</ul>
</ul>
My code:
HTML
<div class="expandable">
<ul class="list">
</ul>
</div>
JavaScript
let list = document.querySelector('.list')
let playslists = {
'Pop' : [
'Recurrent Pop Music',
'1990s Pop - Greates',
'2000s Pop - Greatest',
'2010s Pop - Greatest'
],
'Rock' : [
'Recurrent Rock Music',
'1990s Rock - Greatest',
'2000s Rock - Greatest',
'2010s Rock - Greatest'
]
}
function render(values) {
for(object in playslists) {
// Fill list in HTML document.
}
}
render()
Question
Can i get the keys and values of each object in the for-loop of my render function, to show a list on the webpage, with the keys as category and the values as the playlist names?
Pop - Recurrent Pop Music - 1990s Pop - Greatest - 2000s Pop - Greatest - 2010s Pop - Greatest Rock - Recurrent Rock Music - 1990s Rock - Greatest - 2000s Rock - Greatest - 2010s Rock - Greatest