I am struggling to identify and replace null values with 0's in my object. I was able to access the correct member within the loop, but once it exited, the values were no longer assigned as 0. Working with objects in JavaScript is new to me, so I'm feeling pretty lost. Any assistance on this matter would be greatly appreciated.
var data = {
0 : {
Day1: {
Hours: 6,
Minutes: null
},
Day2: {
Minutes: 45
},
Day3: {
Hours: 8,
Minutes: 15
},
1 : {
Day1: {
Hours: 6,
Minutes: 20
},
Day2: {
Hours: 45,
Minutes: null
},
Day3: {
Hours: 8,
Minutes: 15
}
};
for (var item in data) {
for (var item2 in item) {
item[item2].Hours = item[item2].Hours || 0;
item[item2].Minutes = item[item2].Minutes || 0;
}
}
//Ignore this line. Just assigning onject to angular scope when finished
$scope.timeInfo = data;