I imported an array structure via JSON and parsed it. But I can't access it via index or via forEach. I put out a log of the array, which seems fine, but when I try to log the first element of the first element via array[0][0]
or capsuled for loops it says undefined.
I guess that I somehow messed up my formats, but can't tell.
How may I access the object inside of the arrays without changing the array structure?
Array structure:
[ // Root array (result)
[ // result[0] works fine
[ // result[0][0] = undefined (?)
{ // object I need to access
"ARBPL": "616947 ",
"VDATU": "20210301",
"BDATU": "20210327",
"HALLE": "0001 ",
"PLATZ": "002 ",
"SUBAB": "FW ",
"ABTEI": "FW ",
"T_SCHNEIDP": []
}
]
]
]
Output via Javascript:
// ... this.responseText is from a function, which works just fine.
function getArray(address, fromDate, toDate) {
var linkC = "linkToGetArray" + address + "/" + fromDate + "/" + toDate;
var xmlhttpR = new XMLHttpRequest();
var arr = [];
xmlhttpR.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
arr.push(JSON.parse(this.responseText));
}
};
xmlhttpR.open("GET", linkC, true);
xmlhttpR.send();
return arr;
}
var result = [];
result = getArray(address, fromDate, toDate);
// log of array (works fine)
console.log("result: ");
console.log(result);
// log of first array element (works fine)
console.log("result[0]: ");
console.log(result[0]);
// log of first element of first element (doesn't work, output: undefined)
console.log("result[0][0]: ");
console.log(result[0][0]);
// tried this approach as well, lead to:
// Uncaught TypeError: result[Symbol.iterator().next().value[Symbol.iterator]().next().value is undefined
const [[[obj]]] = result;
I made a screenshot of my browser console to show the array construct and the output from above.