0

How do I set a key of a key-value pair using a variable. I want the new entry to have "30" as key with true as a value, so { "30": true }. Now I get { id: true } instead.

<html>
<head>
    <script src="https://cdn.firebase.com/js/client/2.2.1/firebase.js"></script>
</head>
<body>
<script>
    var ref = new Firebase("https://mydatabase.firebaseio.com/");
    var id="30";
    ref.child("someChild").update({id:true});
</script>
</body>
</html>

1 Answer 1

4
var id="30";
var updatedObj = {};
updatedObj[id] = true;
ref.child("someChild").update(updatedObj);

This should do it.

Sign up to request clarification or add additional context in comments.

1 Comment

yep, its the initalising {} that i wasn't doing that fixed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.