Actually there is JSON code:
"1": { "username": "Игрок", "balance": 228, }
There are many such cells and they are all with different numbers, which, in turn, are in no way connected with each other.
Then I go this way:
var top = []; var fs = require('fs'); var contents = fs.readFileSync("./accounts.json", 'utf8'); template = JSON.parse(contents); const arr = Object.keys(template); for (var i = 0; i < arr.length; i++) { top[top.length] = { "balance": template[arr[i]].balance, "name": template[arr[i]].username } }
And you need to sort the top
array by balance
in each cell of the array.
It should look like this:
It was:
[ "1": { "username": "Игрок", "balance": 228, }, "123": { "username": "Игрок", "balance": 0, } ]
It became:
[ "123": { "username": "Игрок", "balance": 0, }, "1": { "username": "Игрок", "balance": 228, } ]