title: How to call a function after map() loop executed
body: <p>I'm using react-native firebase to save my media into firebase. I have a set of URLs that need to be saved in the firebase. For that, I'm using map() to save one by one. After saving I'm pushing the success URL to the array.
  I need to call a function with this array as a parameter. So I need to call this function after the array is completed.
  I have searched a lot but I did not find a good explanation for this task. Can anyone help me. Thank you.</p>
  
  <pre><code>var mediaArray = []; //array of success callbacks values
  var completedMediaSurveysAnswers = [{}, {}, {}]; //object array of URLs and media types
  completedMediaSurveysAnswers.map((i) =&gt; {
    try {
      const storage = firebase.storage();
      const mRef = storage.ref('portal').child('Survey/Image/user/' + uuidv4() + 'media');
      mRef.putFile(i.urlPath, {
          contentType: i.mediaType
        })
        .on('state_changed', snapshot =&gt; {},
          err =&gt; {
            console.log('Failed to upload file to firebase storage')
          },
          uploadedFile =&gt; {
            // Success
            this.setState({
              mediaPath: uploadedFile.downloadURL
            })
            mediaArray.push(this.state.mediaPath)
          });
    } catch (error) {
      console.log(error)
    }
  })
  
  //need to call this function after loop is done
  saveAnswers(mediaArray)
  </code></pre>