I'm using p5. I've written a function outside of the preload() function and called it within the preload() function. The function looks like this:
const logStuff = () => {
/*37:*/ var JSONfile = loadJSON('data.json')
/*38:*/ console.log(JSONfile)
/*39:*/ let testLat = JSONfile.Sheet1[0].latitude
/*40:*/ let testLong = JSONfile.Sheet1[0].longitude
}
The console reads like this:
v {}
v Sheet1: Array(50)
   0: {state: "Alaska", latitude: 61.385, longitude: -152.2683}
   1:...49:
index.js:39 Uncaught (in promise) TypeError: Cannot read property '0' of undefined
    at createStateButtonObject (index.js:39)
    at preload (index.js:71)
    at p5._start (p5.js:51283)
    at new p5 (p5.js:51639)
    at _globalInit (p5.js:50603)
createStateButtonObject @ index.js:39
preload @ index.js:71
_start @ p5.js:51283
p5 @ p5.js:51639
_globalInit @ p5.js:50603
Promise.then (async)
56.../core/main @ p5.js:50628
o @ p5.js:34
(anonymous) @ p5.js:38
43../accessibility/color_namer @ p5.js:43475
o @ p5.js:34
r @ p5.js:51
(anonymous) @ p5.js:55
(anonymous) @ p5.js:18
(anonymous) @ p5.js:20
What am I doing wrong?
 
    