How to get the for a label?

Dynamically create option from the select.
select_model_iphone function() {
 var array = Array.from($('#price_block .change_model_iphone .item label')).map(len => len.innerHTML);
 var select = document.getElementById('select_model');
 select.innerHTML = `${array.map(el => `<option value="${el}">${'iPhone' + el}</option>`)}`
}

How to get the value label for = '' $('#price_block .change_model_iphone .item label')
and place option value = " ?
June 3rd 19 at 19:28
3 answers
June 3rd 19 at 19:30
Solution
$('#select_model').html(
 $('#price_block .change_model_iphone .item label')
.toArray()
 .map(n => `<option value="${$(n).attr('for')}">iPhone ${$(n).text()}</option>`)
)
thank you - isabell26 commented on June 3rd 19 at 19:33
June 3rd 19 at 19:32
Solution
var item = $('#price_block .change_model_iphone .item label');
var for = item.attr('for');
console.log ('for');
June 3rd 19 at 19:34
Solution
In pure js for the first element it finds:
document.querySelectorAll('#price_block .change_model_iphone .item label')[0].getAttribute('for')

for all that match the selector
document.querySelectorAll('#price_block .change_model_iphone .item label').forEach((item) => console.log(item.getAttribute('for')));

Find more questions by tags JavaScriptjQuery