title: Remove Object in Firebase? (JavaScript)
body: <p>I'm trying to loop through an object in my app and delete old messages after there are 30 messages already in the Database. Here is my code so far:</p>
  
  <pre><code>var ref1 = firebase.database().ref("chatRooms/" + rm + "/messages");
  var query = ref1.orderByChild("time");
  
  query.once("value").then(function(l) {
      l.forEach(function(d) {
        ref1.once("value").then(function(snapshot1) {
        var ast = snapshot1.numChildren(); // Getting the number of children
        console.log(ast);
        if (ast &gt; 29) {
          d.remove();
  
        }
      });
    });
  });
  </code></pre>
  
  <p>The only problem is that I receive the following error for each one: </p>
  
  <blockquote>
    <p><b>SCRIPT438: Object doesn't support property or method 'remove'</b>. </p>
  </blockquote>
  
  <p>If anyone knows how to fix this, or knows of an alternative, I'd appreciate it!</p>