title: How to get index of an array in promise
body: <p>This is my simple code which just adds a question in a database and then get an id as the result and then tries to add <code>questionId</code> in all <code>answer.questionId</code></p>
  
  <pre><code>var size = questions.length;
  
  for(var i=0; i&lt;size; i++){                  
      $http.post(url + "questions", questions[i]).success(function(result){
          questions[i].answers = questions[i].answers.map(function(answer){
              return answer.questionId = result;
          });
      });
  }
  </code></pre>
  
  <p>But promise calls in the end of the loop, therefore, question[i] - undefined since <code>i = size</code>;</p>
  
  <p>How to solve the problem ?</p>