I am trying to create a dynamic table in Javascript which will show the contents of an array(This array will have multiple name).

For EX: var array = ["one","two","three","four"];

The table with Columns "Date" and "Name" should display something like this:

Date              Name

26-06-2021     One

27-06-2021     One

03-07-2021     Two

03-07-2021     Two

Basically the table will represent weekend dates and the names.

in Softwares+OS+Programming by

1 Answer

0 votes
I suggest you to create a js function. The array will be a parameter of the function (this way you can use it with multiple variables). So it will look something like this:

function loadTable(names) {

for(let i = 0; i < names.length; i++) {

   let row = table.insertRow();
   let date = row.insertCell(0);
   date.innerHtml = "insert date here";

   let name = row.insertCell(1);

   name.innerHtml = names[i];



var array = ["one", "two", "three", "four"];

loadTable(array); //calling the function
by 1
6,808 questions
28,914 answers
6,779 users