This post will discuss how to get all options of a select in JavaScript and jQuery.

1. Using jQuery

With jQuery, you can use the .each() method, which is a concise and less error-prone way to iterate over the DOM elements.

JS


HTML



Edit in JSFiddle

 
To filter the selected options, you can use the :selected property.

JS


HTML



Edit in JSFiddle

 
A better alternative is to use the jQuery.map() instead.

JS


HTML



Edit in JSFiddle

2. Using JavaScript

In pure JavaScript, you can loop through each <option> using for-of statement:

JS


HTML



Edit in JSFiddle

 
Alternatively, you can use the Array.prototype.map() method:

JS


HTML



Edit in JSFiddle

That’s all about getting all options of a select in JavaScript and jQuery.