I have a loop which I want to compile an object for the frontend.
The loop sets a user, hours and timestamp variable from which I want to dynamically create the new object.
This is what I have so far which does not work as it obviously just replaces the user. Any help would be great as the best way to go about this, thanks.
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;
};
// example of wanted final output
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
}
}
Things[i].usergive you as it will only be overwriting if it is the same each time, could you show an example of what is inThings