As you can list the variables in the objects with the highest value?

I have a json file
{obj1:{value:0},obj2:{value:3},obj3:{value:2},...}
How can I withdraw the following list
obj2, value:3
obj3, value:2
obj1, value:0
April 19th 20 at 12:06
1 answer
April 19th 20 at 12:08
Solution
json = {obj1:{value:0},obj2:{value:3},obj3:{value:2}}

Object.entries(json) // the object to an array
 .map(( [key, val] ) => [key, val.value]) // remove unnecessary
 .sort((a, b) => b[1] - a[1]) // sort
 .map(a => `${a[0]}, value:${a[1]}`) // converting to string
 .join('\n') // join
And let's say if there is 100 objects you can display only a certain number say 10 - kyla.Hettinger0 commented on April 19th 20 at 12:11
.slice(0, 10)
to the array to use, that is, to cut the first 10 pieces - lisa commented on April 19th 20 at 12:14
Thank you - kyla.Hettinger0 commented on April 19th 20 at 12:17

Find more questions by tags JSONJavaScript