js extract options from select 1

js extract options from select

// @florinrelea
const selectElementId = 'example'
const htmlOptionsCollections = document.getElementById(selectElementId).options
const options = Array.from(htmlOptionsCollections).map(el=> el.textContent)

Here is what the above code is Doing:
1. We get the HTMLCollection of options from the select element
2. We convert the HTMLCollection to an array
3. We map the array to get the textContent of each option

Similar Posts