Can you format the code (either put 3 backticks before it and 3 after, or use the button in the text area)? It’s very difficult to read.
Anyway, it’s not being reinitialised: console.log can be executed immediately, so it logs the empty array
following. Getting the JSON from a server takes time, it’s asynchronous. You need to render stuff out in the getJSON callback, so that you get the data then do stuff with it. At the minute you have an empty array, JS tries to loop through it, there’s nothing there so nothing happens; at some future point, some data maybe comes back from the AJAX call, but nothing will be done with it