title: How to add values in an array inside an array in AngularJS
body: <p>I apologize if my title sounds so confusing, as I don't know how to exactly word it. Basically, this is what I'm trying to do. </p>
  
  <p>For example, I have the following array:</p>
  
  <pre><code>var sourceArray = [
       { question: "Question 1", inputType: "radio", answer: "Answer 1", id: "1" },
       { question: "Question 1", inputType: "radio", answer: "Answer 2", id: "2" },
       { question: "Question 1", inputType: "radio", answer: "Answer 3", id: "3" },
       { question: "Question 2", inputType: "radio", answer: "Answer 1", id: "4" },
       { question: "Question 2", inputType: "radio", answer: "Answer 2", id: "5" },
       { question: "Question 2", inputType: "radio", answer: "Answer 3", id: "6" }
  ]
  </code></pre>
  
  <p>I want to restructure this so that it'll look like this:</p>
  
  <pre><code>var newArray = [
       {
        question: "Question 1", inputType: "radio", 
        choices: [{answer: "Answer 1", id: "1"},
                  {answer: "Answer 2", id: "2"},
                  {answer: "Answer 3", id: "3"}
                 ]},
       {
        question: "Question 2", inputType: "radio", 
        choices: [{answer: "Answer 1", id: "4"},
                  {answer: "Answer 2", id: "5"},
                  {answer: "Answer 3", id: "6"}
       ]}
  ]
  </code></pre>
  
  <p>Answers are grouped by question, so if the next question in the <code>sourceArray</code> is the same with the current, it will push the answers into the <code>choices</code> array.</p>
  
  <p>Is this possible in AngularJS using angular.forEach?</p>
  
  <p>Any help will be appreciated. </p>
  
  <p>Thank you as always for your responses.</p>