I have an array of objects in Javascript. Without using any HTML, I need to add buttons for each object in the array. I know how to make buttons in Javascript like so:
//Create the button
var button = document.createElement("button");
But I'm not sure how to add one for each object in the array. Here is my array code for my array:
var items = [
{
name: "cake",
price:"7.00",
quantity:4
},
{
name:"fries",
price:"8.00",
quantity:3
},
{
name:"brownie",
price:"5.00",
quantity:2
},
{
name:"candy",
price:"9.00",
quantity: 12
},
]
I have more objects in my array but I have only added a few to minimize question and I want 'name' to be used as the label of the button. I know I will need to use a for loop but I'm stuck on what to write in the loop. I have tried searching about this question on Google but I wasn't able to find anything that showed how to do this in Javascript I only found other languages which I have not learned yet. Also I have already this link: https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
I want to use the button as a like button. Each item will have a button, when that button is clicked on, the item will be displayed in a list. For ex: the user likes cake and fries so my "list" will say cake and fries. Each button can only be clicked once. This is similar to the concept of adding items to a shopping care but I'm using it for liked items.