1. Классика, цикл for {}
const info = {
title: 'Hello!!!',
graduatesCount: 2000,
areYouChampion: true,
technologies: ['Front', 'Back', 'Devops']
}
let techSelect = document.createElement('select');
for (let i = 0; i < info.technologies.length; i++) {
let render = document.createElement('option');
render.append(info.technologies[i]);
techSelect.append(render);
}
document.body.append(techSelect);
2. Цикл for..in
let techSelect = document.createElement('select');
for (let i in info.technologies) {
let render = document.createElement('option');
render.append(info.technologies[i]);
techSelect.append(render);
}
document.body.append(techSelect);
3. Цикл for..of
let techSelect = document.createElement('select');
for (let i of info.technologies) {
let render = document.createElement('option');
render.append(i);
techSelect.append(render);
}
document.body.append(techSelect);
4. Метод массива forEach()
let techSelect = document.createElement('select');
info.technologies.forEach(i => {
let render = document.createElement('option');
render.append(i);
techSelect.append(render);
});
document.body.append(techSelect);
5. Метод массива reduce()
let techSelect = document.createElement('select');
techSelect.append(info.technologies.reduce((acc, i) => acc+`<option>${i}</option>`, ''));
document.body.append(techSelect);