I used to have an array of arrays and used a sort function to get the proper order like:
var sampleArr = [
[272, 'Some Title', 1, 1],
[281, 'Some Other Title', 1, 2],
[287, 'Another Title', 2, 1]
];
sampleArr.sort(sortCourses);
function sortCourses(a, b){
if (a[3] == b[3]) {
return (a[2] - b[2]);
} else {
return (a[3] - b[3]);
}
}
That is the desired result, however we have changed to have the id as a property and the value of the property an array like:
var sampleObj = {
272: ['Some Title', 1, 1],
281: ['Some Other Title', 1, 2],
287: ['Some Other Title 2', 2, 1]
};
This makes our life a lot easier with lookups for that id, however I am not sure how to sort it.
Can anyone shed some light on the best way to accomplish this? Do I need to convert it back to an array with a function and then run the same sort function? If so, how would I convert the sampleObj back to the original format?
Thanks.