I am writing some code that will create multiple buttons based on the array given to the function. What I have done is that I used the array.prototype.forEach to test the function out by printing the contents of the array on the console. When that worked I tried to make some buttons but the buttons are not showing up on the page. I have tried adding document.body.appendChild(element); but all that did was give me errors. Is there a way to create multiple buttons based on an array of items using array.protoype.forEach?
This is my code:
var array = ["bill", "harry", "john", "timothy"];
array.forEach(element =>
document.createElement(element)
// I tried adding document.body.appendChild(element); here but kept giving me errors
);