In JavaScript, I am currently learning about accessing objects and sorting them based on multiple conditions. As a beginner in JavaScript, this may seem like a very basic question to some. My task involves sorting based on the 'status' field.
var issues = cf.getEventMessage(reply); // All data stored in 'issues'
var assigneeTasks = {};
for(var i=0; i<issues.length; i++){
var record = issues[i];
if(assigneeTasks[record.assigneemail] == undefined){
assigneeTasks[record.assigneemail] = [];
}
assigneeTasks[record.assigneemail].push(record); // Sorted according to 'assigneemail'
}
Now the variable assigneeTasks
contains:
{"[email protected]":
[
{"id":"T-728","assignedTo":"dev","assigneemail":"[email protected]","duedate":"2017-09-29","status":"Open"},
{"id":"T-727","assignedTo":"dev","assigneemail":"[email protected]","duedate":"2017-09-29","status":"In Progress"},
{"id":"T-726","assignedTo":"dev","assigneemail":"[email protected]","duedate":"2017-10-04","status":"Open"},
{"id":"T-679","assignedTo":"devt","assigneemail":"[email protected]","duedate":"2017-09-29","status":"Under Review"},
{"id":"T-645","assignedTo":"dev","assigneemail":"[email protected]","duedate":"2017-09-27","status":"In Progress"}
],
"[email protected]":
[
{"id":"T-728","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-09-29","status":"Open"},
{"id":"T-727","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-09-29","status":"In Progress"},
{"id":"T-726","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-10-04","status":"Open"},
{"id":"T-679","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-09-29","status":"Under Review"},
{"id":"T-645","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-09-27","status":"In Progress"}
]
}
The desired output should be:
{"[email protected]":
[
{"id":"T-728","assignedTo":"dev","assigneemail":"[email protected]","duedate":"2017-09-29","status":"Open"},
{"id":"T-726","assignedTo":"dev","assigneemail":"[email protected]","duedate":"2017-10-04","status":"Open"},
{"id":"T-727","assignedTo":"dev","assigneemail":"[email protected]","duedate":"2017-09-29","status":"In Progress"},
{"id":"T-645","assignedTo":"dev","assigneemail":"[email protected]","duedate":"2017-09-27","status":"In Progress"},
{"id":"T-679","assignedTo":"devt","assigneemail":"[email protected]","duedate":"2017-09-29","status":"Under Review"}
],
"[email protected]":
[
{"id":"T-728","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-09-29","status":"Open"},
{"id":"T-726","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-10-04","status":"Open"},
{"id":"T-727","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-09-29","status":"In Progress"},
{"id":"T-645","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-09-27","status":"In Progress"},
{"id":"T-679","assignedTo":"paul","assigneemail":"[email protected]","duedate":"2017-09-29","status":"Under Review"}
]
}