Looking to create an unordered list with vanilla JS, using an array of objects to populate the list. Struggling a bit on how to accomplish this.
Here is my current code:
let myObj = [
{name: "Harry Potter", author: "JK Rowling"},
{name: "Hunger Games", author: "Suzanne Collins"},
{name: "Lord of the Rings", author: "J. R. R. Tolkien"},
{name: "Game of Thrones", author: "George R.R. Martin"},
{name: "Percy Jackson", author: "Rick Riordan"},
];
console.log(myObj);
let myUL = document.createElement("UL");
myUL.setAttribute("id", "myUL");
document.getElementById("myDiv").appendChild(myUL);
for (const item of myObj) {
document
.getElementById("myUL")
.appendChild(document.createElement("LI"));
}
<div id="myDiv"></div>
Struggling to format my list to look like this:
- JK Rowling: Harry Potter
- Suzanne Collins: Hunger Games
- J. R. R. Tolkien: Lord of the Rings
- George R.R. Martin: Game of Thrones
- Rick Riordan: Percy Jackson
Any tips on accomplishing this using vanilla JS would be appreciated!