Define an array with the values you want to populate in the <select> element. var fruits = ["Apple", "Banana", "Orange", "Grapes", "Mango"]; Create a <select> element in your HTML markup. <select id="mySelect"></select> Iterate through the array and create <option> elements for each value, then append them to the <select> element. Here's an example: document.addEventListener("DOMContentLoaded", function () { var fruits = ["Apple", "Banana", "Orange", "Grapes", "Mango"]; var selectElement = document.getElementById("mySelect"); for (var i = 0; i < fruits.length; i++) { var option = document.createElement("option"); option.value = fruits[i]; option.text = fruits[i]; selectElement.appendChild(option); } }); In this example, the JavaScript code runs ...
Comments