Posts

Showing posts with the label ionic

Asynchronous access to an array in Firebase

Image
Here is my code: var userRef = new Firebase ( "https://awesome.firebaseio.com/users/" ); var tokenRef = userRef . child ( key + '/tokens' ); tokenRef . once ( 'value' , function ( snapshot ){ var userTokenSync = $firebase ( tokenRef ); var userTokens = userTokenSync . $asArray (); console . log ( userTokens ); console . log ( userTokens [ 0 ]); for ( var i = 0 , len = userTokens . length ; i < len ; i ++) { console . log ( userTokens [ i ]); } console . log ( 'done' ); }) This code gets the tokens of a user from firebase, and I just want to browse the tokens array. Here is what the console gives me: As you can see, I cannot access the array. Do you have any idea of how I could do this? Thanks in advance.