0

I have a JSON hash of stock symbols:

"NASDAQ":{ 
    "CYTX":{"last":0.73,"change":47.3,"volume":199962,"low":0.62},
    "YECO":{"last":2.19,"change":58.7,"volume":23467,"low":1.78},
    "AMDA":{"last":0.505,"change":34.5,"volume":77822,"low":0.403},
    "ADMP":{"last":2.75,"change":22.2,"volume":111213,"low":2.30
    "KBLMR":{"last":0.39,"change":29.8,"volume":900473,"low":0.27},
 }

Is there a built-in way in Javascript to sort this based on the "change" column (i.e. not the hash keys of CYTX, YECO, etc...)?

So the result will be (sorted by change descending):

"NASDAQ":{ 
    "YECO":{"last":2.19,"change":58.7,"volume":23467,"low":1.78},
    "CYTX":{"last":0.73,"change":47.3,"volume":199962,"low":0.62},
    "AMDA":{"last":0.505,"change":34.5,"volume":77822,"low":0.403},
    "KBLMR":{"last":0.39,"change":29.8,"volume":900473,"low":0.27},
    "ADMP":{"last":2.75,"change":22.2,"volume":111213,"low":2.30
 }
Brent Heigold
  • 1,213
  • 5
  • 24
  • 50
  • 3
    No because object properties don't have an order. – Titus Aug 23 '18 at 03:25
  • 1
    Not in this way, you can sort an array of objects, but you can't sort the properties (in this case, YECO, CYTX, ...). It will be better if you create a pure array of objects using the key as a property (eg: "name":"YECO") and using the .sort method https://www.w3schools.com/js/js_array_sort.asp – F.Igor Aug 23 '18 at 03:31
  • 1
    You can not sort in this way, it's better if you create new array instead only pure Json.Sharing link-- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort – Prasanna Aug 23 '18 at 03:36
  • 1
    this question is more or less like this one .you can refer to this link https://stackoverflow.com/questions/979256/sorting-an-array-of-javascript-objects – Prasanna Aug 23 '18 at 03:50

0 Answers0