I am not sure how to phrase this question but I hope it is understandable
In Angular 6 I have a GET request that returns a JSON object like this
"fieldA": [
{
"displayValue": "value1",
"id": "A"
},
{
"displayValue": "value2",
"id": "B"
}
],
"fieldB": [
{
"displayValue": "value1",
"id": "0"
},
{
"displayValue": "value2",
"id": "1"
},
],
"FieldC": [
{
"displayValue": "value1",
"id": "47"
},
{
"displayValue": "valuen",
"id": "94"
},
]
}"fieldA": [
{
"displayValue": "value1",
"id": "A"
},
{
"displayValue": "value2",
"id": "B"
}
],
"fieldB": [
{
"displayValue": "value1",
"id": "0"
},
{
"displayValue": "value2",
"id": "1"
},
],
"FieldC": [
{
"displayValue": "value1",
"id": "47"
},
{
"displayValue": "valuen",
"id": "94"
},
]
}
if I iterate over this with this code
for(let item in this.response) {
console.log(item);
this.schFields.push(item);
}
I correctly get each of the field names. There could be a variable number of field names each with variable numbers of values
Now I need to list the values for each of the fields stored in the schFields array
I cannot see how to use the value read from the array as a variable
if I know the field name then it works fine, like
for(let item of this.response.fieldA) {
let itemelem = { "entity_id" : item.id, "entity_name" : item.displayValue };
this.items.push(itemelem);
}
but when the fieldA part needs to be a variable I have not been able to find a solution.