Reputation: 75
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.
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);
}
Upvotes: 0
Views: 391
Reputation: 760
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);
}
Upvotes: 1
Reputation: 6742
Outcome[k].outcome
It's basically just a property of the object stored into the Outcome[].
Upvotes: 1