I'm trying to iterate through an array of objects and retrieve all the data from each object, but for some reason, I'm only getting the data from the last object. Can anyone help me figure out why it's skipping the first one?
Here is the array I'm working with:
item {
_id: new ObjectId("627ed71261b2bd692178bdca"),
sn: 'fN300W15076fd5bg6dwf',
merchantId: '9000000058800',
merchantName: '999',
networkType: '220509',
__v: 0,
terminalId: '987654321',
resultData: [
// data for multiple objects within the array
]
}
----------------------------------------------------
// More items with their respective data
Despite having multiple objects in the array, I'm only able to access the resultData from the last object.
If you're curious about my code implementation, here is how it looks:
async getLogByTPE() {
let result;
// Code logic for retrieving and processing data
}
In this function, I aim to fetch the resultData from each object within the array, but I seem to be stuck only accessing the data from the last object. Any insights or assistance would be greatly appreciated!