I have some nested data that I am trying to extract from a big object. I’ve parsed the JSON and can find keys in the object no problem but I cannot for the life of me figure out why I can’t use forEach on a key that’s essentially an array of objects.
My data set looks like this (I’ve removed some bits for ease). This is an extract from currentSnapshot (as per below).
errors: [
{ id: 1, count: 0, delta: 0, checks: 395 },
{ id: 2, count: 14, delta: 0, checks: 395 },
{ id: 3, count: 0, delta: 0, checks: 209 },
{ id: 6, count: 17, delta: 0, checks: 75846 },
{ id: 7, count: 7, delta: 0, checks: 71392 },
{ id: 8, count: 231, delta: 1, checks: 8541 }
],
My JS then is fairly simple.
const currentSnapshot = data.current_snapshot
const updatedSnapshot = [{}]
currentSnapshot.errors.forEach((array) => {
array.forEach((obj) => {
const objId = obj.id.toString()
const name = semAuditHeadings[objId]
if (name !== undefined) {
updatedSnapshot[0][name] = obj.count
}
})
})
But I am getting a TypeError: array.forEach is not a function error. Weirdly enough this only started happening after I activated my linter, so not sure whether the linter could impact the build?
This is for a Node (Express) API.
I’ve tried to convert it to an array manually. I’m able to check the length of the array, and it’s accurate, but no luck