Search code examples
arraysjsonapiiterationresponse

working with API json response - how do I extract nested array data and store it in a JavaScript array?


Below is a screenshot of the API response (from console). I need to extract the text of each "outcome" and store it in a JavaScript array.

enter image description here

I can iterate through the "Outcome" array, but how do I drill down further to get to the text (value) of each outcome? I feel like I'm missing something simple...

function processData(myObj) { //this is the callback function for the API ajax request
  var course_learning_outcomes_array = [];
  for (var k = 0; k < myObj.catalog.Course.Outcomes_Folder.Outcome.length; k++) {
    course_learning_outcomes_array.push(myObj.catalog.Course.Outcomes_Folder.Outcome[k]);
  }
  console.log(course_learning_outcomes_array);
}


Solution

  • Outcome[k].outcome
    

    It's basically just a property of the object stored into the Outcome[].