I have a huge database of waifu’s and I want to get a random name with the corresponding image url, how would I do that.
A bit of the json:
{
"waifuID": {
"1": {
"names": "Megumin",
"img_url": "https://s4.anilist.co/file/anilistcdn/character/large/b89361-xH1t0q5WeAN8.png"
},
"2": {
"names": "Mai Sakurajima",
"img_url": "https://s4.anilist.co/file/anilistcdn/character/large/b127222-IY5iDRuXLY8i.png"
},
"3": {
"names": "Zero Two",
"img_url": "https://s4.anilist.co/file/anilistcdn/character/large/b124381-pkTKi6HHNuVR.png"
}
}
}
I want to get a random ID and display the name and img-url thats in that ID, how would I do that in javascript?
EDIT: I tried doing
const WaifuNDB = require("../../Database/WaifuNameDB.json")
const waifunames = 56
const waifunames2 = Math.floor(Math.random() * waifunames)
var waifunames3 = waifunames2
var waifu = WaifuNDB.waifuID.waifunames3.names
console.log(waifu)
The error it gave was,
(node:9072) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'names' of undefined
But it didn’t work
:c