0

i have an array of objects. example [object Object]. This array is basically first object is the code of U.S and the second object is its fullname.

{AK: "Alaska", AL: "Alabama", AR: "Arkansas", AZ: "Arizona", CA: "California", CO: "Colorado"},

does anyone know how to sorted alphabetically?

Carlitos Overflow
  • 609
  • 3
  • 13
  • 41
  • 3
    Objects are not arrays, and can't be sorted. – p.s.w.g Nov 21 '14 at 19:02
  • any suggestions on how it can be done taking different approach? – Carlitos Overflow Nov 21 '14 at 19:04
  • What is your real task? – PM 77-1 Nov 21 '14 at 19:06
  • 2
    The question as it stands is not very clear. Can you describe exactly what you're trying to accomplish? – p.s.w.g Nov 21 '14 at 19:06
  • Refer this solution - http://stackoverflow.com/a/1129270/2231822 – KrisPrajapati Nov 21 '14 at 19:07
  • Try this http://stackoverflow.com/questions/1134976/how-may-i-sort-a-list-alphabetically-using-jquery - They use a list but the idea is transferable. – Gjohn Nov 21 '14 at 19:08
  • @CarlitosOverflow You can put all your object keys in another array, and then sort that array. After that you can access object by array keys. – Varun Chakervarti Nov 21 '14 at 19:12
  • @CarlitosOverflow After that you can access object by array keys. You don't need to sort object every time, just sort that array once and use anytime in your code. – Varun Chakervarti Nov 21 '14 at 19:18
  • 1
    This is either a duplicate of [Sorting JavaScript Object by property value](http://stackoverflow.com/questions/1069666/sorting-javascript-object-by-property-value) or [Sorting a JavaScript object by property name](http://stackoverflow.com/questions/1359761/sorting-a-javascript-object), depending on whether you want to order by name or value. – apsillers Nov 21 '14 at 19:34

0 Answers0