createElement and array

Hello, I want create a list of element of an array, for example I have this array ‘a’, ‘b’, ‘c’, ‘d’, ‘e’;
and I want put this array in a list or in a table there is no difference i think, just so how to made???:joy:Thanks.

What have you tried so far? If you can share what you’ve got so far with us, and explain where you’ve got stuck, it will be easier for us to guide you.

i want only know how to insert array in a list, I have tryed nothing i can’t.
I have an array of five elements and i would create a list of this array, you can show me an example?

A quick Google search brought up this page with examples: https://www.w3schools.com/js/js_arrays.asp

I would like to create a dinamic list, i would like to use createElement for this array but i don’t know…you can show me some example???

Google to the rescue: https://www.w3schools.com/jsref/met_document_createelement.asp

Have you ever used Google to look up information? We expect you to do your own homework and get back to us with what you’ve tried when you’ve gotten stuck. :slight_smile:

var arr=['a','b','c','d','e'];
//First I create a ul element
var ul=document.createElement('ul');
//Then I append it at the body
document.getElementsByTagName('body')[0].appendChild(ul);
//Via for loop for every value in the arr
//I create a li element I set the array value as innerHTML
//and at final I append it at the ul
for(var i=0;i<arr.length;i++){
  var li=document.createElement('li');
  li.innerHTML=arr[i];
  ul.appendChild(li);
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.