How to get the text from the DIVS, and on their basis to create a select?

There is a block whose content is generated dynamically. The result is:
<div class="text">text1</div>
<div class="text">text2</div>
<div class="text">text3</div>


On the basis of content .text you need to create a select. Like this:
<select name id="select">
 <option value="text1">text1</option>
 <option value="text2">text2</option>
 <option value="text3">text3</option>
</select>
June 3rd 19 at 19:20
1 answer
June 3rd 19 at 19:22
Solution
const array = Array.from(document.getElementsByClassName('text')).map(len => len.innerHTML),
 select = document.getElementById('select');

select.innerHTML = `${array.map(el => '<option>' + el + '</option>').join(")}`;
thank you.
Do not tell me how when you select the option in the select, add the relevant .text class .active? - isabell26 commented on June 3rd 19 at 19:25
, javascript.ru/forum/misc/42598-dobavit-klass-dlya-... - Myrtis commented on June 3rd 19 at 19:28
not exactly.
contents .text stuff is not only option, but in the value of this option?
what would have happened:

<option value="text1">text1</option>
 <option value="text2">text2</option>
 <option value="text3">text3</option>
- isabell26 commented on June 3rd 19 at 19:31
, https://jsfiddle.net/Svupol/rk8q3zpn/19/ - Myrtis commented on June 3rd 19 at 19:34
works! huge thank you) - isabell26 commented on June 3rd 19 at 19:37

Find more questions by tags JavaScriptjQuery