title: How to access snapshot value outside of loop?
body: <p>I'm using Firebase with JavaScript and I want to assign <code>user.fcmkey</code> to an outside variable key.</p>
  
  <p>The following is my code but doesn't access the key value and prints <code>NA</code>. How can I access snapshot value outside of the snapshot block.</p>
  
  <pre><code>var key="NA";
  
  firebase.database().ref('users').child("1234567896").once('value', function(snap) {
      const user = snap.val()
      const userKey = snap.key;
      const myKey=user.fcmkey;
      key = myKey  
  });
  </code></pre>