I am trying to print a list of objects using vanilla javascript. In my loop, only the last item is getting printed. How do I fix this? I tried appending each li to a variable (node) and then append it to my ul id but that did not work. Here is the fiddle:
https://codepen.io/anon/pen/LLgZzw?editors=1011
HTML
<ul id="list"></ul>
JS
let list = document.getElementById('list');
let obj = {
"codepen": 'www.codepen.io',
"jsfiddle": 'www.jsfiddle.com',
"jsbin": 'www.jsbin.com'
};
function printList(obj){
for(let key in obj){
console.log(key);
list.innerHTML = `<li><a href= ${obj[key]}>${key}</a></li>`;
}
//list.appendChild(li);
}
printList(obj);
list.innerHTML +=<li><a href= ${obj[key]}>${key}</a></li>;using+=