Iterate over the a
array and create element inside that instead.
If you want to try to avoid creating variables when not needed, you can use appendChild
(which returns the appended element):
const ul = document.body.appendChild(document.createElement('ul'));
for (const item of ['one','two',"three","four"]) {
ul.appendChild(document.createElement('li')).textContent = item;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…