Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created April 23, 2020 15:52
Show Gist options
  • Save azamsharp/57b19d609e9031e7e3319a9a78892a8c to your computer and use it in GitHub Desktop.
Save azamsharp/57b19d609e9031e7e3319a9a78892a8c to your computer and use it in GitHub Desktop.
// dishList is a UL element in HTML
let dishList = document.getElementById("dishList")
// METHOD 1
/*
for(let index = 0; index < dishes.length; index++) {
let dish = dishes[index]
let dishItem = `
<li>
<img class="dish-image" src="${dish.imageURL}" />
<b>${dish.title}</b>
<p>${dish.description}</p>
<b>$${dish.price}</b>
</li>
`
// dishList is UL
// insertAdjacentHTML is going to add the HTML to the end of UL
dishList.insertAdjacentHTML('beforeend',dishItem)
} */
// METHOD 2 (ARRAY HELPERS)
// map array helper is also known as transformation operator
let dishItems = dishes.map(function(dish) {
return `<li>
${dish.title}
<p>${dish.description}</p>
</li>`
})
dishList.innerHTML = dishItems.join(" ")
console.log(dishItems)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment