N
N
ninja op op2020-05-23 11:47:48
JavaScript
ninja op op, 2020-05-23 11:47:48

How to fetch values ​​from JSON array?

How to select from JSON array. I tried array[0] but it returns undefined.

In this case, the array itself:

{
    "197892920": {
      "balance": "0.00",
      "banned": false,
      "admin": false
    },
    "225750107": {
      "balance": "950.00",
      "banned": false,
      "admin": false
    },
    "321223555": {
      "balance": 1000,
      "banned": false,
      "admin": false
    },
    "458132521": {
      "balance": "0.00",
      "banned": false,
      "admin": false
    },
    "532334365": {
      "balance": 1000,
      "banned": false,
      "admin": false
    },
    "535271173": {
      "balance": 1000,
      "banned": false,
      "admin": false
    },
    "546674311": {
      "balance": 500,
      "banned": false,
      "admin": 1
    },
    "582877546": {
      "balance": 1000,
      "banned": false,
      "admin": false
    },
    "586589172": {
      "balance": 1000,
      "banned": false,
      "admin": false
    }
  }


How can I display all elements of the array, but in a certain format:
User #user ID
Balance:
#balance Admin: #admin
Ban: #banned

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Banan44, 2020-05-23
@Banan44

This is not an array, but an object, make the right selection

for (let id in object) {
   console.log(id)
   console.log(object[id].balance)
   console.log(object[id].banned)
   console.log(object[id].admin)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question