DEV Community

Discussion on: Append multiple elements using append()

Collapse
 
isa56 profile image
isa56 • Edited

I have a question about this (2 years later, sorry): can I append items that are on a array?
I want to render li elements with text from localStorage (it is a basic DOM exercise I'm planning) inside a ul, so I was planning on using an array as I do not know how many elements are going to be created.
Is there any way to do it?

Edit: I know editing DOM is costly, so I do not know if it is best to do something like:

for (let i=0; i<listItems.length; i++) {
   unorderedList.append(listItems[i])
}
Enter fullscreen mode Exit fullscreen mode

Would this be appropriate?