menu search
brightness_auto
Ask or Answer anything Anonymously! No sign-up is needed!
more_vert

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.

1 Answer

more_vert
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
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
Welcome to Answeree, where you can ask questions and receive answers from other members of the community.
...