I am having issues figuring out how to find the nulls in my object and replace them with 0's. I was able to access the correct member at one point but once it left the loop their were no longer assigned the 0. I am fairly new to working with objects in js so I am pretty lost. Any help 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;
for inloops, theitemanditem2refers to the keys, not the values (my point is thatitem[item2]doesn't make sense). So for example,itemwill be"0"and"1"