I am working with an object structure retrieved from an API response. I need to extract various attributes from the data, which is nested within another object. Can someone assist me in achieving this in a cleaner way without relying on hardcoded indices?
{
"objects": [
{
"id": "2132",
"type": "year",
"name": "product",
"Version": "0.3",
"data": {
"CTimestamp": "2018-08-15T21:53:52+00:00",
"createdBy": "abc",
"CYCreateTimestamp": "2018-08-15T21:53:52+00:00",
"Code": "HO",
"Abbreviation": "xyz",
"Description": "abcd",
"cycleYearIdentifier": 2132,
"id": "2132"
}
}
],
"pages": {
"totalPages": 1,
"totalResources": 1
}
}
I am specifically looking to retrieve the 'code' key from the "data" object under "objects" - without hardcoding any index values. Let's assume that the complete result is stored in a variable named result or response. As a beginner in JavaScript, I hope to find something similar to Python dictionaries where we can use .get method to fetch values using keys if they exist.
Expected outcome : "HO"
for this particular API response.