How to get the number of options in the dropdown list with JavaScript?

HTMLJavascriptProgramming Scripts

To get the count of options in a dropdown list, use the length property in JavaScript.


You can try to run the following code to find the number of options in the drop-down −

Live Demo

<!DOCTYPE html>
      <form id="myForm">
         <select id="mySelect">
         var val = document.getElementById("mySelect").length;
         document.write("<br>Options in the DropDown list: "+val);
Updated on 23-Jun-2020 08:45:21