In my code, I am trying to create an object for the frontend using a loop.
Within the loop, variables are set for user, hours, and timestamp, which I want to use to dynamically build the new object.
This is what I have attempted so far, but it's not working as expected. Any assistance in resolving this issue would be greatly appreciated. Thank you!
var Things = { /* big dump of data */ };
var usersHours = {};
for (var i = Things.length - 1; i >= 0; i--) {
var user = Things[i].user;
var hours = Things[i].hours;
var timeStamp = Things[i].timeStamp;
var hoursAdd = {};
hoursAdd[timeStamp] = hours;
usersHours[user] = hoursAdd;
};
// This is the desired final output structure
var usersHours = {
user1 : {
1406178757855 : 10:00,
1406178743473 : 04:00,
1406178759600 : 04:44
},
user2 : {
1406178475847 : 01:30,
1406193847384 : 07:00,
1406984783487 : 08:44
},
user3 : {
1406173847787 : 01:40,
1406139847873 : 07:14,
1406183748374 : 08:34
}
}