I have the following object with nesting array:
var foobar = {
"foo1": ["bar1", "bar2"],
"foo2": ["bar3", "bar4"]
}
I need to convert it to:
{
"foo1": {"bar1":"bar1", "bar2":"bar2"},
"foo2": {"bar3":"bar3", "bar4":"bar4"}
}
The function below iterates through the first element of the object successfully:
$scope.regonal = {};
angular.forEach(foobar, function(value, key) {
angular.forEach(value, function(v) {
$scope.regonal[key][v] = v;
});
});
... but fails on the second with error:
TypeError: Cannot set property 'bar3' of undefined
foo3magically appear from? Is that a typo?