0
   var num = counter;
            var foo= {};
            foo["id" + num]= 3;
            ref2.child("id" + num).update({: 3});

This is just a snippet of my code, and i'm using firebase legacy (i know i need to switch, but haven't yet). So I'm trying to either set (or update, whichever is the best way) a current child which is id1, id2, id3 etc. I'm trying to access a specific id value (which I've done using previous code and is stored in counter) and set that id value to something. However, i can't do so without using a specific key. Please help!! Thanks

Zaid Mirza
  • 3,540
  • 2
  • 24
  • 40
Taras Tataryn
  • 21
  • 1
  • 8
  • It's hard to see exactly what you'll need to do without seeing the [minimal, but complete code+JSON (as text, no screenshot please) that reproduces the problem](http://stackoverflow.com/help/mcve). – Frank van Puffelen Dec 05 '16 at 15:17

1 Answers1

0

It looks like you're trying to use a dynamic value for the data key? You're close.

Create an object using square bracket notation for the keys and drop that into the update method. For example if you wanted to do ref.update({id42: 'hello'}) where the id is dynamic:

var someData = {};
var somethingDynamic = 42;
var someValue = 'hello';
someData['id' + somethingDynamic] = someValue;
ref.update(somedata);
Lesley
  • 1,395
  • 12
  • 11