When the page is ready I have a function which runs first and get data from a google spreadsheet and using them to create content of the main container in the html. Then the rest of the script follows which depends on the content that is created from the previous function. For example there is an array which should get as values the elements that have been created before.
The first function take few seconds because there a lot of data and as I did some debugging, it seems that while the content is still loading the script has been moved on and the array seems empty.
Both parts of the script have been tested and work fine separate one from each other.
I am using .getJSON() if that helps, in order to get the data.