I have been unable to figure out how to turn a nested array such as:
var array = [
[['firstName', 'Henry'], ['codeName', 'Etta'], ['email', '[email protected]'], ['weight', 180], ['occupation', 'repo']],
[['firstName', 'Bruce'], ['codeName', 'DK'], ['email', '[email protected]'],
['weight', 200], ['occupation', 'enforcement']]
];
into an object such as
var array = [
{firstName: 'Henry', codeName: 'Etta', email: '[email protected]', weight: 180, occupation: 'repo'},
{firstName: 'Bruce', codeName: 'DK', email: '[email protected]', weight: 200, occupation: 'enforcement'}
];
Below is what I've come up with so far, but it is clearly not producing the results I need.
function arrIntoObject(array) {
var obj = {};
array.map(function(a) {
a.map(function(e) {
obj[e[0]] = e[1];
});
});
return obj;
}
This seems like a question that would have been asked by now, but after hours I haven't been able to find a similar question, so I would appreciate any help or guidance here. Thanks!