I have an Object of Objects. (because I want to use associative array, so object of objects, not numeric array of objects)
var tasks=new Object();
for(...){
tasks[foo-i]={};
tasks[foo-i].index=....;
tasks[foo-i].name=...;
}
I have a function that’ll output the name of the tasks, but they have to be according to the index in ascending order. So, I’ll have to have a temporary sort-function.
How would you do that?
Thanks
Option 1: Output in order of the keys on the task object:
Perhaps there is a more elegant way, but this way gets all the tasks keys out of the object, sorts them and then uses the ordered index array to cycle through the original object in key order (if I understood correctly what you’re trying to do).
You could use tasks.keys as a shortcut to getting the object indexes, but that is not universally available so you’d have to have an alternate way of doing it anyway.
Option 2: Output in order of the embedded index tasks[i].index:
Reading your question again, I realized that there may be another way to interpret your question. Perhaps you meant in index order where it’s the .index data right next to the .name, not the index key on the tasks object. If so, that would take a different routine: