I've come across this issue before, but I'm having difficulty navigating through a nested structure. I can't seem to find any guidance in the right direction. Here is the object I'm attempting to parse:
const nestedArray =
{ id : 100
, interval : 1000
, enable : true
, topics:
[ { topic1:
[ { id: 0, 'error-code' : 100 }
, { id: 1, status : 200 }
, { id: 2, mode : 300 }
] }
, { topic2:
[ { id: 0, count : 100 }
, { id: 1, total : 200 }
, { id: 2, operation : 300 }
] } ] }
My goal is to loop through nestedArray
, extract the topic name from topics
(e.g., "topic1"), and retrieve the associated key-value properties within the nested array (e.g., "id" and "error-code").
I'm relatively new to this and have attempted methods like Object.entries, Object.keys, Object.values, and recursive functions. However, I haven't been able to get the desired values or encountered errors due to incompatible methods with the Object type. If someone could provide insight into how this can be accomplished, it would be greatly appreciated.