Reputation: 132
How can I randomize the values of these objects? And can you assign it randomly every 10-20 minutes?
const fs = require('fs');
var winrate = Math.floor(Math.random() * 101);
// create a JSON object
const gamesg = [{
"ID": 1,
"GAME_CAMPS": "SG",
"GAMENAME": "FISHING GOD",
"IMG_PATH": "./SG/1 FISHING GOD.png",
"GAME_IMG": "1 FISHING GOD.png",
"WINRATE": winrate
},......................................{
"ID": 55,
"GAME_CAMPS": "SG",
"GAMENAME": "HONEY HUNTER",
"IMG_PATH": "./SG/55 HONEY HUNTER.png",
"GAME_IMG": "55 HONEY HUNTER.png",
"WINRATE": winrate
}
];
Upvotes: 0
Views: 75
Reputation: 14165
Here is a solution for creating a random value and to place that value into a JavaScript object:
const gamesg = [{
"WINRATE": 0
}, {
"ID": 1,
"WINRATE": 0
}, {
"ID": 2,
"WINRATE": 0
}, {
"ID": 3,
"WINRATE": 0
}, {
"ID": 4,
"WINRATE": 0
}];
let output = gamesg
.map(g => { g.WINRATE = Math.floor(Math.random() * 101); return g});
console.log(output);
Upvotes: 1