I have an array of objects in the following format:
var log=[
{
billkey:"Name",
billvalue:"ABC"
},
{
billkey:"Department",
billvalue:"Computer"
}];
and I want to convert it into a single object like this:
var log={
"Name":"ABC",
"Department":"Computer"
};
I attempted the following approach:
for(var i=0;i<log.length;++i){
pushToAry(log[i].billkey, log[i].billvalue);
}
function pushToAry(name, val) {
var obj = {};
obj[name] = val;
ary.push(obj);
}
However, this results in pushing a new object into the array every time, leading to:
var ary =[
0:{
"Name":"ABC"
},
1:{
"Department":"Computer"
}];
How can I properly convert this array of objects into a single object?