title: javascript - adding properties to array objects
body: <p>I'm trying to loop through a pipe delimited list passed to a function, split it out into an array based on the pipe as a separator, and then break each item out into its component parts, where the format is as follows:</p>
  
  <p>"76:1167|76:1168"</p>
  
  <p>so that the array would be: surveyQuestions[0] = 76:1167. And then that would be split up into : surveyQuestions[0].question = 76 and surveyQuestions[0].answer = 1167.</p>
  
  <p>And this is the code I'm using, but the values come back undefined when I try to add the properties to each array item.</p>
  
  <pre><code>function answerSurvey(survey){
  
  var surveyResults = survey.split("|");
  
  for (var i=0;i&lt;surveyResults.length;i++){
  
      var surveyResult = surveyResults[i].split(":");
      var surveyQ = surveyResult[0];
      var surveyA = surveyResult[1];
      surveyResults[i].surveyQ = surveyQ;
      surveyResults[i].surveyA = surveyA;
      console.log(surveyResults[i].surveyQ + "|" + surveyResults[i].surveyA)
  }
  
  }
  
  answerSurvey("76:1167|76:1168");
  </code></pre>