O
O
ojiekcahdp2021-01-14 22:27:47
JavaScript
ojiekcahdp, 2021-01-14 22:27:47

Random selection of ID from JSON?

I have a JSON, I need to extract a random id from it, and of course the value in it.
How can I do that?

[
{
    "id": 124124,
    "firstname": "Районный",
    "lastname": "Прокурор",
    "warns": 0,
    "role": 11,
    "flip": 0,
    "rank": "Участник",
    "ban": false,
    "isBanned": "Нет",
    "tempban": 0,
    "mute": 0,
    "mutesleft": 0,
    "violations": 0,
    "botmute": 0,
    "nick": "хай"
  },
  {
    "id": 123123,
    "firstname": "Кто",
    "lastname": "Никто",
    "warns": 0,
    "role": 11,
    "flip": 0,
    "rank": "Участник",
    "ban": false,
    "isBanned": "Нет",
    "tempban": 0,
    "mute": 0,
    "mutesleft": 0,
    "violations": 0,
    "botmute": 0
    "nick": "пока"
  },
  {
    "id": 125125,
    "firstname": "Крутой",
    "lastname": "Поц",
    "warns": 0,
    "role": 1,
    "flip": 0,
    "rank": "Участник",
    "ban": false,
    "isBanned": "Нет",
    "tempban": 0,
    "mute": 0,
    "mutesleft": 0,
    "violations": 0
    "nick": "привет"
  }
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2021-01-14
@YuriyVorobyov1333

const item = items[Math.floor(Math.random() * items.length)];

And then get everything you need from this object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question