let arr = ['Main', 'Products', 'About us', 'Contacts']
let menu = document.getElementsByClassName('menu')[0]
let li = document.createElement('li')
let user = (param1, param2) => {
for (const user of param2) {
li.innerText = user
param1.append(li)
}
}
user(menu, arr)
menu.insertAdjacentHTML('beforeend', arr
.map(n => `<li>${n}</li>`)
.join('')
);
// или
menu.append(...arr.reduce((acc, n) => (
(acc[acc.length] = document.createElement('li')).textContent = n,
acc
), []));
// или
for (const n of arr) {
menu.appendChild(document.createElement('li'));
menu.lastChild.innerText = n;
}
let li = document.createElement('li')
внутрь цикла. let arr = ['Main', 'Products', 'About us', 'Contacts']
let menu = document.getElementsByClassName('menu')[0]
let user = (param1, param2) => {
for (const user of param2) {
let li = document.createElement('li')
li.innerText = user
param1.append(li)
}
}
user(menu, arr)