How To Create An Each Loop, But Keep The Data Together
I have an exercise block with one word and 4 syllables. In my json it looks like this: { 'main_object': { 'id': 'new', 'getExerciseTitle': 'TestFrontEnd', 'language': 'nl_NL', 'a
Solution 1:
Here is some JavaScript solution for your problem defined in question title:
var json = {
"main_object": {
"id": "new",
"getExerciseTitle": "TestFrontEnd",
"language": "nl_NL",
"application": "lettergrepen",
"main_object": {
"title": "TestFrontEnd",
"language": "nl_NL",
"exercises": [{
"word": "huisarts",
"syllables": [
"Huis",
"arts",
"",
""
]
},
{
"word": "voetbal",
"syllables": [
"Voet",
"bal",
"",
""
]
}
]
},
"dataType": "json"
}
}
var exercise = json.main_object.main_object.exercises;
exercise.forEach(function(ex) {
console.log("For the word " + ex.word + " the syllabus are:");
ex.syllables.forEach(function(sy, i) {
console.log(i+1 + " " + sy);
})
})
Post a Comment for "How To Create An Each Loop, But Keep The Data Together"