Sorting an object?

Posted by dfjhdfjhdf on Stack Overflow See other posts from Stack Overflow or by dfjhdfjhdf
Published on 2010-05-31T13:18:01Z Indexed on 2010/05/31 13:22 UTC
Read the original article Hit count: 128

Filed under:

How to sort this object lexicographically by its keys:

var obj = {'somekey_B' : 'itsvalue', 'somekey_A' : 'itsvalue');

so that it outputs like this:

for (k in obj) {
  alert(k + ' : ' + obj[k]); //first "somekey_A : itsvalue"; then "somekey_B : itsvalue"
}

© Stack Overflow or respective owner

Related posts about JavaScript