Reputation: 83
I'm using Javascript and I'm facing a problem in adding data in the Firebase with dynamic key
this is my variable
var stuID = snap.child("StudentID").val();
I'm adding it in this way
DataBaseRef.set({
stuID : stuID
});
it keeps setting is key to "stuID" instead of the actual value
Upvotes: 1
Views: 815
Reputation: 83093
You should use the square bracket notation, as follows:
var myObj = {};
myObj[stuID] = 'myValue'; //or myObj[stuID] = stuID; if it is what you want
DataBaseRef.set(myObj);
Upvotes: 2