D'oh. Easy answer with sort:

$H(MyHash).keys().sort(function(a,b) {
                return MyHash[a].val - MyHash[b].val;
        });


--Mike

On May 5, 2006, at 11:29 AM, Mike Nosal wrote:

Quick Prototype.js hash question.

Given:
MyHash = {"Alpha" : {name:"Foo",val:3},
"Delta" : {name:"Bar",val:2},
"Beta" : {name:"Baz",val:4} }

I want to display this set ordered by key - Alpha,Beta,Delta and by val - 2,3,4
Prototype.js helps with the hash:
$H(MyHash).keys().sort() will give me Alpha, Beta, Delta
but I've not figured out how to extract the keys in sorted order "Delta,Alpha,Beta" according to val.

Thoughts?
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to