How to Create a Dropdown List with Array Values using JavaScript? Last Updated : 02 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report To add elements to the select element from the JavaScript array, We can also get selected values in the dropdown list using JavaScript. Here we will populate the dropdown list with an array.Below are the methods to create a dropdown list with array values:Table of ContentUsing Pure JavaScriptUsing jQueryUsing Pure JavaScriptUtilizes pure JavaScript to dynamically populate a dropdown list with array values. The GFG_Fun() the function iterates through the array, creating and appending option elements to the dropdown.Example: In this example, the length property is used to traverse the elements of the array and on each element create an option element and append this new element to the select element by appendChild() method. HTML <!DOCTYPE html> <html> <head> <title> Populate dropdown list with array values </title> </head> <body style="text-align:center;"> <h2> Click on Button to Populate dropdown list with array values </h2> <select id="arr"> <option>Dropdown Items</option> </select> <br><br> <button onclick="GFG_Fun();"> Click Here </button> <h2 id="GFG" style="color: green;"></h2> <script> let res = document.getElementById('GFG'); let select = document.getElementById("arr"); let elmts = ["HTML", "CSS", "JS", "PHP", "jQuery"]; // Main function function GFG_Fun() { for (let i = 0; i < elmts.length; i++) { let optn = elmts[i]; let el = document.createElement("option"); el.textContent = optn; el.value = optn; select.appendChild(el); } res.innerHTML = "Elements Added"; } </script> </body> </html> Output:OutputUsing jQueryEmploys jQuery to dynamically populate a dropdown list with array values. The GFG_Fun() function leverages jQuery's $.each to iterate through the array, creating and appending option elements to the dropdown.Example: In this example, the each() method is used to traverse the elements of the array and on each element create an option element and append this new element to the select element by append() method in JQuery. HTML <!DOCTYPE html> <html> <head> <title> Populate dropdown list with array values </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> </head> <body style="text-align:center;"> <h2> Click on Button to Populate dropdown list with array values </h2> <select id="arr"> <option>Dropdown Items</option> </select> <br><br> <button onclick="GFG_Fun();"> Click Here </button> <h2 id="GFG" style="color: green;"></h2> <script> let res = document.getElementById('GFG'); let select = document.getElementById("arr"); let elmts = ["HTML", "CSS", "JS", "PHP", "jQuery"]; // Main function function GFG_Fun() { $.each(elmts, function (i, p) { $('#arr').append($('<option></option>') .val(p).html(p)); }); res.innerHTML = "Elements Added"; } </script> </body> </html> Output:Output Comment More infoAdvertise with us P PranchalKatiyar Follow Improve Article Tags : JavaScript CSS-Misc HTML-Misc HTML-Questions CSS-Questions +1 More Similar Reads JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read HTML Interview Questions and Answers HTML (HyperText Markup Language) is the foundational language for creating web pages and web applications. Whether you're a fresher or an experienced professional, preparing for an HTML interview requires a solid understanding of both basic and advanced concepts. Below is a curated list of 50+ HTML 14 min read Introduction to JavaScript JavaScript is a versatile, dynamically typed programming language used for interactive web applications, supporting both client-side and server-side development, and integrating seamlessly with HTML, CSS, and a rich standard library.JavaScript is a single-threaded language that executes one task at 7 min read JSON Web Token (JWT) A JSON Web Token (JWT) is a standard used to securely transmit information between a client (like a frontend application) and a server (the backend). It is commonly used to verify users' identities, authenticate them, and ensure safe communication between the two. JWTs are mainly used in web apps an 7 min read CSS Interview Questions and Answers CSS (Cascading Style Sheets) is the language that styles and organizes web pages. It makes websites visually appealing and user-friendly. Mastering CSS is crucial whether you're a beginner or a seasoned developer. This guide presents 60+ CSS interview questions and answers, categorized to help you p 15+ min read Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie 15+ min read JavaScript Coding Questions and Answers JavaScript is the most commonly used interpreted, and scripted Programming language. It is used to make web pages, mobile applications, web servers, and other platforms. Developed in 1995 by Brendan Eich. Developers should have a solid command over this because many job roles need proficiency in Jav 15+ min read Top 95+ Javascript Projects For 2025 JavaScript is a lightweight, cross-platform programming language that powers dynamic and interactive web content. From real-time updates to interactive maps and animations, JavaScript brings web pages to life.Here, we provided 95+ JavaScript projects with source code and ideas to provide hands-on ex 4 min read Functions in JavaScript Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code. It can take inputs, perform actions, and return outputs.JavaScriptfunction sum(x, y) { return x + y; } console.log(sum(6, 9)); // output: 15Function Syntax 5 min read Like