I'm trying to pass a two dimensional array into a JavaScript function but I only get the first element of the two dimensional array. Below is an excerpt of my code:
header = [['Objective','summary'],['Status','txtHealth']];
...
function setTableHeader(data){
console.log(data);
var table = document.getElementById('tblData').tHead.insertRow(0);
for (var i = 0; i < header.length; i++)
table.insertCell(i).innerHTML = data[i];
};
/*calling the function*/
setTableHeader.apply(this,header);
The console log shows only ['Objective','summary'], is it because the function gets passed only the pointer to the memory location of the first memory block of the array?
I'm new to webdev and I'm also curious if I should be using global variables whenever I can rather than local variables?
apply? Try just calilng the functionsetTableHeader(header)