I am facing some difficulties with JSON and JavaScript as I am a beginner in this area. Currently, I am attempting to iterate through all the keys["name"] of this JSON data.
var l = [{
"pages": [
{
"name": "Scan",
"elements": [
{
"type": "radiogroup",
"name": "Gender",
"title": "Gender",
"choices": [
"Male",
"Female"
]
},
{
"type": "text",
"name": "Name",
"title": "Name"
},
{
"type": "text",
"name": "Age",
"inputType": "number"
},
{
"type": "text",
"name": "E-mail",
"title": "E-mail",
"validators": [
{
"type": "email"
}
],
"inputType": "email"
}
]
},
{
"name": "Q",
"elements": [
{
"type": "radiogroup",
"name": "What Country Food you like?",
"choices": [
"Thailand",
"Japan",
"Italy"
],
"colCount": 3
},
{
"type": "text",
"name": "What is your favorite food",
"visibleIf": "{What Country Food you like?} notempty"
}
]
}
]
}];
I have been trying to achieve this using the following code snippet:
l.forEach(function(element) {
console.log(element);
});
However, I am only seeing 2 arrays in the console.log output:
0: Array[name:"Scan", element:Array(4)}
1: Array[name:"Q", element:Array(2)}
I am hoping to get the keys["name"] to appear as follows:
(Scan, Name, Age, Gender, E-mail, "What Country Food you like?", "What is your favorite food")