0

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);
}

2 Answers 2

1
Outcome[k].outcome

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yup, something simple! Thank you so much @maio290. I will accept this as the answer.
1

You can access each element in the array and then simply push the outcome property, as follows:

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].outcome);
  }
  console.log(course_learning_outcomes_array);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.