showing results for - "how to populate a list in html with javascript"
Beatrice
09 Jan 2018
1function makeList() {
2    // Establish the array which acts as a data source for the list
3    let listData = [
4        'Blue',
5        'Red',
6        'White',
7        'Green',
8        'Black',
9        'Orange'
10    ],
11    // Make a container element for the list
12    listContainer = document.createElement('div'),
13    // Make the list
14    listElement = document.createElement('ul'),
15    // Set up a loop that goes through the items in listItems one at a time
16    numberOfListItems = listData.length,
17    listItem,
18    i;
19
20    // Add it to the page
21    document.getElementsByTagName('body')[0].appendChild(listContainer);
22    listContainer.appendChild(listElement);
23
24    for (i = 0; i < numberOfListItems; ++i) {
25        // create an item for each one
26        listItem = document.createElement('li');
27
28        // Add the item text
29        listItem.innerHTML = listData[i];
30
31        // Add listItem to the listElement
32        listElement.appendChild(listItem);
33    }
34}
35
36// Usage
37makeList();
queries leading to this page
using ul and arrayjavascript put items of array into lijs create a list of html elements based on a listcreate ul from array javascriptjavascript create unordered list from arrayhow to create a list in html from array in javascriptjavascript array to ulput array object to html ul lijavascript array to list of objects javascript in a ul il listhow to generate the html of an unordered list from raw data javascriptjavascript for loop to create unordered listpopulate ul with list domadd an array to html as ul javascriptbuild list based on dom valuejavascrript populate a div with listhtml function fill listhow to render an array as an unordered listfill list in htmlpopulate a list from data javascriptdisplay list item after loading arrayhow to populate a list in javascripthow to generate a list in javascripthow to populate a list in html with javascriptuse a for loop to populate an unordered listjavascript convert a list to a ul elementconvert array to li in javascriptlist item generator java javascriptjavascript from array create lihtml populate listarray list lijavascript create ul from arrayhow to populate a list in jsgenerate beautiful html list from javascript arrayhow to make list in to array javascriptshow array in ul jshow to put an array in an ol in jsjavascript how to return an array in an object as an ulhow to list ajavascript array elemnt in html ul tag 3fadd array of strings to ul list javascriptpopulate html list with javascriptjavascript populate html listjavascript array as ulcreate list from array javascripthow to populate list through jsul to list jsadd array of strings to unordered list element javascripthow to add listitems to a list with innerhtml when they are objects in an arrayload list from array jsreturn list of ularray to ul li javascriptato populate list in jsputting array inside ul javascriptgenerate the html of an unordered list from raw data javascriptpopulate a list in jsmake a ul out of a list jsmaking a ul from a saved arrayarray inside of a 3cul 3e javascriptjavascript convert array to html listpopulate a list in javascripthow to populate a list in html with javascript