Javascript function to display 1 random element from an Array using
<h1>Random Array Element</h1>
<ul id="array-elements"></ul>
<button onclick="displayRandomArrayElement(['apple', 'banana', 'orange'])">
Display Random Array Element
</button>
<script>
function displayRandomArrayElement(array) {
// Get a random index from the array
const randomIndex = Math.floor(Math.random() * array.length);
// Get the element at the random index
const randomElement = array[randomIndex];
// Create an li element
const li = document.createElement('li');
// Set the text content of the li element to the random element
li.textContent = randomElement;
// Append the li element to the DOM
document.getElementById('array-elements').appendChild(li);
}
</script>