An object is created here:
var versionsLegend={}, versionsCounter=1, currentVersionNum=0;
Then in a loop the values should be set - either to a zero value currentVersionNum depending on condition or to other values with a counter versionCounter
The problem is that with the counter it is set as expected, but when the condition is true and it sets the 0 value it turns the object into an Array and wipes out the previous data.
for (var i = 0; i < success.data.data.length; i++) {
if (success.data.data[i][0].Items.selected) {
$scope.views.series.push(success.data.data[i][0].Items.id);
versionsLegend = {
[success.data.data[i][0].Items.id]: currentVersionNum
};
} else {
versionsLegend = {
[success.data.data[i][0].Items.id]: versionsCounter
};
versionsCounter++;
}
}
In the log before this line:
versionsLegend={[success.data.data[i][0].Items.id]:currentVersionNum};
I get Object { 12: 1 } and after Object [ <9 empty slots>, 0 ]
I've omitted the unrelated to the problem parts of the code.
Tried to use .toString() on the object keys - to no avail.