I've recently gotten started with Firebase development in React.js -
At the moment, I'm trying to pull from the database and create a new object with the data.
This is the code:
var arr = firebase.database().ref("news");//this is the ref.
arr.once('value', function (snapshot) {//will return the array value
model = {//this is the model i want to .push()
title: title,
content: content,
img: img,
category: category,
likes: likes,
id: snapshot.val().length//This is where I want to add the arr.length
};
var promise = arr.push(model);
promise.then(function(){
...
})
})
The problem is that arr.push(model) runs BEFORE the model.id variable is loaded.
snapshotargument has aval()function?snapshot.val()get you a javascript object. do you want to get how many children in it?