Just starting out with TypeScript and feeling a bit lost. The data I receive from my BackEnd looks like this:
{
"A": [
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 123,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 111,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 99,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 24,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 21,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 11,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 75,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 76,
"fieldD": 0,
},
{
"fieldA": 0,
"fieldB": "A",
"fieldC": 13,
"fieldD": 0,
}
],
And my TypeScript class structure for handling this data is as follows:
export class someDataFromBackend{
public data: {
[key: string]: {
fieldA: string;
fieldB: number;
fieldC: string;
fieldD: number;
};
}[];
constructor(data: any) {
this.data = data;
}
}
My issue at the moment is that I'm struggling to access any of the elements. For example, I want to create a new Array with values from all fieldC. Or perhaps something as simple as printing the fieldC from the second array inside "A" (the one with value 111).
Even when I attempt to console.log(someDataFB.data)
, it returns undefined.