This is more of a JavaScript Closure question than a Firebase question. In the following code, the Firebase callback isn\'t recognizing the variable myArr in the parent scop
The child_added event is not immediately executed, therefore is not synchronous and you can't rely on it to have executed, before the log call at the end of your function.
The procedure is: