I am new to coding and trying to get this problem right. I tried calling the index of the arrays but it prints out columns. Out dev environment is REPL.it, the virtual machine uses node v10.16.0 and help would be greatly appreciate
Input
tableData = [
["first_name", "last_name", "city", "state"],
["Elisabeth", "Gardenar", "Toledo", "OH"],
["Jamaal", "Du", "Sylvania", "OH"],
["Kathlyn", "Lavoie", "Maumee", "OH"]
]
Desired Output
output = [
{ first_name : "Elisabeth", last_name : "Gardenar", city: "Toledo", state : "OH" },
{ first_name : "Jamaal", last_name : "Du", city: "Sylvania", state : "OH" },
{ first_name : "Kathlyn", last_name : "Lavoie", city: "Maumee", state : "OH" }
]
What I have tried so far is this:
function convertTable(){
var p=console.log;
const [header,...rows] = tableData;
var tableObj = new Object;
var intermediateVal = [];
var finalArr = [];
for(var vals=0;vals<rows.length;vals++){
var row = rows[vals]
for (var key=0,val=0;key<header.length;key++,val++){
tableObj[header[key]]=row[val]
}
p(tableObj)
}
}
convertTable(tableData)