I want to display the Object properties (Label, Icon, Href) from a randomly chosen object from the array. How should I go about this, This is what I have so far.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var myArray = [{
label: "Pears",
icon: "Pears.png",
href: "./Pears"
}, {
label: "Appels",
icon: "Appels.png",
href: "./Appels"
}, {
label: "Mango",
icon: "Mango.png",
href: "./Mango"
}, ];
var randomItem1 = myArray[Math.floor(Math.random()*myArray.length)];
var randomItem2 = myArray[Math.floor(Math.random()*myArray.length)];
var randomItem3 = myArray[Math.floor(Math.random()*myArray.length)];
var randomItem4 = myArray[Math.floor(Math.random()*myArray.length)];
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById("randomItem1").innerHTML = randomItem1;
document.getElementById("randomItem2").innerHTML = randomItem2;
document.getElementById("randomItem3").innerHTML = randomItem3;
document.getElementById("randomItem4").innerHTML = randomItem4;
});
</script>
<p>Random 1</p>
<div id = "randomItem1"> </div>
<!--Label value-->
<!--Icon value-->
<!--Href value-->
<p>Random 2</p>
<div id = "randomItem2"> </div>
<p>Random 3</p>
<div id = "randomItem3"> </div>
<p>Random 4</p>
<div id = "randomItem4"> </div>
</body>
</html>
innerHTML = Object.values(randomItem1).join()