how can I print the "obj" value after the .on method is done with looping all items in my firebase and increments all the values? In short, what I am trying to do here is that, once the looping is done, I want to print the result ("obj") to the console.
Appreciate any help here! Thanks.
var obj = {
"20120101" : {"neutral": 0, "positive": 1, "negative": 2},
"20120101" : {"neutral": 0, "positive": 1, "negative": 2}
} //above is just an example on the structure of the object
var fbase = new Firebase("https://<appname>.firebaseio.com/");
fbase.on('child_added', function(snapshot){
var item = snapshot.val(); //has the attributes of: date & classification
var date_str = item.date;
if (!obj[date_str]){
//initialise the counting;
obj[date_str] = { "negative": 0, "neutral": 0, "positive" : 0 };
}
obj[date_str][item.classification] += 1;
});
console.log(obj);