I have a large .json file that I need to make accessible in a .js file (to be passed to Vue for processing). I can fetch the data and log the data within the fetch, and have pushed it to a globally available variable. However, while the variable returns and looks correct in the console, I can't access a single index (using brackets - it returns undefined) and thus can't loop through the returned data. If bring a fraction of that data into the local file it works as expected, but the arrays look similar in in the console and I can't determine how the full array is different, or how to reformat it to be able to loop through the data.
var rooms = [];
var anti = [
{
"Name": "EXIT STAIR",
"Number": "E-120",
},
{
"Name": "STAFF TOILET",
"Number": "E-116",
},
{
"Name": "PATIENT TOILET",
"Number": "D-123",
}
];
fetch("mp-rooms.json")
.then(response => response.json())
.then(data => rooms.push(...data.roomList))
console.log('roomtestouter', rooms, rooms[3], rooms.at(2));
console.log('local', anti, anti[0], anti.at(1));
This is what I see in the console:
I have reviewed How do I return the response from an asynchronous call?, but it does not answer my questions, as I need the data in a external variable, not handled inside the async call. Pushing the data within the call is the only working method I have found with much research and experimentation.