Trying to merge two arrays, one for column headers:
cNames = ["Year","Count"]
And another for data:
mData = ["2005",50212,"2006",51520,"2007",52220,"2008",52143]
The goal is to combine them like this:
[
{
Year: "2005",
Count: 50212
},
{
Year: "2006",
Count: 51520
},
{
Year: "2007",
Count: 52220
},
{
Year: "2008",
Count: 52143
}
]
Tried to achieve this with:
var data;
for (var i=0; i < mData.length; i++) {
for (var j=0; j < cNames.length; j++) {
data[cNames[j]]=mData[i];
}
}
. . . but the output was not as expected. Any suggestions on how to fix this would be greatly appreciated!