I am currently facing an issue where I am trying to incorporate data from a JSON file into my array, but for some reason, the information is returning as 'undefined' because nothing is being created in my array. Below are the contents of the JSON file:
"histogram": [
{
"type": "Comedy",
"count": 4
},
{
"type": "Action",
"count": 5
},
{
"type": "Romance",
"count": 6
},
{
"type": "Drama",
"count": 1
},
{
"type": "SciFi",
"count": 4
}
]
}
The current code that I have been utilizing involves using the push() function to add information, however, it doesn't seem to be functioning correctly at the moment. Here is the snippet of the code in question:
let movies;
function preload() {
movies = loadJSON('movies.json');
}
count = [];
var c0 = movies.histogram[0].count;
count.push(c0);
I would greatly appreciate any assistance or guidance with this matter. Thank you!