Ive got this Random array function that should pick a scope from an array and then pick randomly from the randomly selected scope but it is returning undefined any ideas? I does pick up the file perfectly.
function dynamicgenerator(array, name) {
//"name" is only for one array
let arrayPush = [];
try {
let arrayJson = require(`../json/${array}`)
//console.log(arrayJson)//returning true
for (i in arrayJson) {
arrayJson.push(arrayPush[`${i}`])
console.log(arrayPush)
let randomScope = Math.floor(Math.random() * arrayPush.length); //chooses a scope array out of arrayPush
let randomObject = Math.floor(Math.random() * randomScope.length);
let ret = randomScope[randomObject]
return ret;
}
} catch (e) {
console.log('DynamicGen returned err whether planned or not.')
let rand = Math.floor(Math.random() * name.length);
let ret = name[rand]
return ret;
}
}