I use a javascript object as a map.
Let's say I populate it like this:
for (var i=0;i<100;i++) {
var key = "A"+(i%10);
oj[key] = i;
}
This creates a map with 10 keys. The value of 100 and 10 are just fictitious. it could be 10000 events which create a map of 3000 or similar.
I now want to print the map alphabetically:
//
// First I transfer the items in an array.
//
array = [];
for (var i in oj) {
array.push(i);
}
//
// then I sort them
//
array.sort();
//
// now I can process them
//
str = '';
for (var i=0;i<array.length;i++) {
str+= array[i]+' '+oj[array[i]]+'\n';
}
Can anybody suggest a better* way ?
*better meaning faster !!!
Thanks a lot