I want to ask how can we delete data from Firebase's real-time DB after a certain number of msgs using javascript.
The code:
function getData() {
firebase.database().ref("/" + room_name).on('value', function (snapshot) {
document.getElementById("output").innerHTML = "";
snapshot.forEach(function (childSnapshot) {
childKey = childSnapshot.key;
childData = childSnapshot.val();
if (childKey != "Purpose") {
firebase_message_id = childKey;
message_data = childData;
//Start code
named = message_data["name"];
message = message_data["message"];
like = message_data["like"];
timed= message_data['time']
row = "<h4> "+ named+"<b class='time'> "+timed+"</b>"+"</h4><h4 class='message_h4'>"+ message +"</h4><button class='btn btn-warning' id='"+firebase_message_id+"' value='"+like+"' onclick='updateLike(this.id)'><span class='glyphicon glyphicon-thumbs-up'> Like: "+ like +"</span></button><hr>";
document.getElementById("output").innerHTML += row;
//End code
var objDiv = document.getElementById("output");
objDiv.scrollTop = objDiv.scrollHeight;
}
});
});
}
getData();