I'm having a very simple JSON file which looks like:
{
"seasons" : {
"s_1" : {
"episodes" : 7
},
"s_2" : {
"episodes" : 21
},
"s_3" : {
"episodes" : 22
},
"s_4" : {
"episodes" : 30
},
"s_5" : {
"episodes" : 18
},
"s_6" : {
"episodes" : 12
}
}
}
and I want to randomly select a s_ x
value from seasons when parsing the file:
var random = Math.floor(Math.random() * 6) + 1;
$.getJSON('js/data.json', function(data) {
console.log(data.seasons.s_+random);
});
this obviously does not work. How would be the correct way? Thanks