title: How do I loop all Firebase children in React Native?
body: <p><strong><em>ANSWER AT BOTTOM OF POST</em></strong>
  (ALSO SEE @soutot ANSWER)</p>
  
  <p>I have successfully gained text output from my <code>Firebase</code> code and so I know it works. Now I need to loop all the children in <code>Firebase</code>. Coming from swift, the way to do it is to store each item on a tempObject then append that to an array. Then you can simply use that array any way you like. This doesn't seem to work with <code>JavaScript</code>, or I'm doing something wrong. The fully functional FB code I now have is: </p>
  
  <pre><code>componentDidMount(){
      let child = "" 
      var ref = firebase.database().ref("testCategory");
  
      ref.once("value")
      .then(function(snapshot) {
          child = snapshot.child("test1/testHeader").val() 
          this.setState( {    
              child
          })
      }.bind(this)); 
  }
  </code></pre>
  
  <p>I can then successfully print this in console or in <code>&lt;Text&gt;</code>. Now, the problem I'm having is looping all children, adding them to an array, then using that array to display the data. In my head, this is how it should work:</p>
  
  <pre><code>componentDidMount(){
      let child = "" 
      var ref = firebase.database().ref("testCategory");
  
      ref.once("value")
      .then(function(snapshot) {
          snapshot.forEach(function(childSnapshot){
             let tempObject = MyFirebase
             tempObject.testHeader = 
             childSnapshot.val() 
  
             myArray.append(tempObject) //or .push???
          })
          this.setState( {    //PASSING VARIABLE TO STATE
              child   
          })
      }.bind(this)); //BINDING TO SET STATE
  }
  </code></pre>
  
  <p>I know that this is obviously wrong. Creating an object like that doesn't even work... <code>MyFirebase</code> -class looks like this: </p>
  
  <pre><code>render() {
  let testHeader = ""
  let testText = ""   
  )
  }
  </code></pre>
  
  <p>My <code>Firebase</code> database looks like this: 
      <img src="https://i.stack.imgur.com/Lm4hR.png" alt="FB DB">
  (I ignored subText for now)</p>
  
  <p>All suggestions are much appreciated :)</p>
  
  <p><strong><em>WORING CODE</em></strong></p>
  
  <pre><code> //FIREBASE CODE 
  componentDidMount(){
      const ref = firebase.database().ref("testCategory");
  
      ref.once("value")
      .then(function(snapshot) {
          const categories = []
  
          //LOOPING EACH CHILD AND PUSHING TO ARRAY
          snapshot.forEach(item =&gt; {
  
              const temp = item.val();
              categories.push(temp);
              return false;
          });
  
          this.setState( {    //PASSING VARIABLE TO STATE
              child,
              categories
          })
      }.bind(this)); //BINDING TO SET STATE
  }
  </code></pre>