Advanced method of getting dropdown list items in JavaScript

When working with selects, there is the following feature: the variable that stores the reference to the select is an array, the elements of which are the option tags. This means that this variable can be looped over:

let select = document.querySelector('#select'); for (let option of select) { console.log(option); }

Well, or just turn to the item with the desired number:

let select = document.querySelector('#select'); console.log(select[0]);

Loop through all the items in the list and add the value of its value attribute to the end of the text of each item.

enru