title: Firebase - How can I save each object item by a child slug, opposed to their index number?
body: <p>How can I save items in an object as there nested tag (as apposed to there index number). </p>
  
  <p>For instance Im working with the follow data: </p>
  
  <pre><code> {
    "all_items": [
      {
        "id": 900,
        "item_id": 20,
        "name": "First Item",
        "slug": "first-item"
      },
      {
        "id": 800,
        "item_id": 21,
        "name": "Second Item",
        "slug": "second-item"
      }
    ]
  }
  </code></pre>
  
  <p>saving it like so:</p>
  
  <pre><code>var dataRef = new Firebase("https://&lt;firebase-Id&gt;.firebaseio.com/");
  var data=  {"all_items": [....]};      // This is the truncated object above.
  dataRef.update(data); //saving 
  </code></pre>
  
  <p>In firebase it saves each value by their index as seen here:</p>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/EEDjl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EEDjl.png" alt="enter image description here"></a></p>
  </blockquote>
  
  <p>How can I have the first item the <strong>0</strong> to be saved as its items slug <strong>first-item</strong><br>
  and the second item (index number <strong>1</strong>) to save as <strong>second-item</strong>, and so on.</p>
  
  <p>So far I've worked with snapshots like so: </p>
  
  <pre><code>dataRef.child('all_items')once("value", function(snapshot) {
    snapshot.forEach(function(childSnapshot) {
  
      //KEY
      var key = childSnapshot.key();
      console.log('key: ', key); // returns 0 then 1
  
       //VALUE
       var childData = childSnapshot.val();
       console.log('childData: ', childData); //returns first item then second
       console.log('slug: ', childData.slug);//returns 'first-item' then 'second-item'
  
        //issue is here. I would like to use
       key.update(childData.slug)
       //but firebase returns "TypeError: key.update is not a function
  
    });
  </code></pre>
  
  <p>Now that I can log them, how can I save them where I overwrite the index number by its slug? </p>