title: Firebase data is "undefined" when it is not
body: <p>I am trying to retrieve some data from my firebase database, but the value I get is "undefined".</p>
  
  <p><strong>This is how I save the data to the database:</strong></p>
  
  <pre><code>var database = firebase.database();
  
          database.ref().push({
          mainArray: mainArray,
          secondArray: secondArray,
          listname: listName,
          mainLanguage: mainLanguage,
          secondLanguage: secondLanguage,
  
    }, function(error) {
    if (error){
  
      stopLoader();
  
      showSnackbar("An error has occured! Please try again later.");
  }
  </code></pre>
  
  <p><strong>This is how I read the data, but the value of listname is "undefined":</strong></p>
  
  <pre><code> var database = firebase.database().ref().child('codes');
      var codeInput = document.getElementById('mainSearch');
  
      database.on('value', function(snapshot) {
              if (!snapshot.hasChild(codeInput.value)) {
  
                  codeInput.value = "";
                  showSnackbar("A list with this code does not exist!&lt;br&gt;&lt;br&gt;Please try another one.")
              }
              else {
  
                 var data = snapshot.val();
                 var listname = data.listname;
  
  
                 console.log(listname);
  
  
  
              }
          });
  </code></pre>
  
  <p><strong>This is the value I get from the database:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/KstcK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KstcK.png" alt="This is the value I get from the database"></a></p>
  
  <p><strong>This is how the data is structured in the database:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/Xpqm2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xpqm2.png" alt="This is how the data is structured in the database:"></a></p>