Answer the question
In order to leave comments, you need to log in
How to make a random selection of an object from a json file?
In general, there is a users.json file, it stores the data of each user, looks something like this:
[
{
"id": 123123,
"status": "wow"
},
{
"id": 124124,
"status": "yes"
}...
]
Answer the question
In order to leave comments, you need to log in
const users = require('users.json');
const indx = Math.round(Math.random() * users.length);
const user = users[indx];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question