Answer the question
In order to leave comments, you need to log in
How can I list the variables in the objects with the largest value?
I have json file
how can i output something like this list
obj2, value:3
obj3, value:2
obj1, value:0
{obj1:{value:0},obj2:{value:3},obj3:{value:2},...}
Answer the question
In order to leave comments, you need to log in
json = {obj1:{value:0},obj2:{value:3},obj3:{value:2}}
Object.entries(json) // объект в массив
.map(( [key, val] ) => [key, val.value]) // убираем лишнее
.sort((a, b) => b[1] - a[1]) // сортируем
.map(a => `${a[0]}, value:${a[1]}`) // переводим в строки
.join('\n') // соединяем
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question