I find that the code works as I intended (I think). But the last step in which I print the data feels wrong. The way I concatenate the html and js seems abit off. Is there a better way to concatenate this? Am I using the wrong solution to print the data?
// This list I use inside my Array.
const myList = {
Germany : {name : 'Germany', capital: 'Berlin', visited: 'Checked' },
Italy : {name : 'Italy', capital: 'Rome', visited: 'Checked' },
Spain : {name : 'Spain', capital: 'Madrid', visited: 'unchecked' },
}
// My array
const destinations = [];
// Push data from myList to destination-array.
for(var key in myList) {
destinations.push(myList[key]);
}
// This is how write out my data on the page.
for (var i = 0; i < destinations.length; i++) {
document.write("<li><h1>" + destinations[i].name + "</h1><p>" +
destinations[i].capital +
"<input type='checkbox'" + destinations[i].visited + ">")
};
This Is what I am planing to write out at the end.
<li class="all-destinations">
<h3>destinations[i].name</h3>
<div class="container">
<label class="switch">
<input type="checkbox" destinations[i].visited>
</label>
</div>
<p>destinations[i].capital</p>
<hr>
</li>
myListyou can simply do:const destinations = Object.values(myList)