I'm trying to go through this JSON object and grab some values out of it.
let currentPage = "
{
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "xaswoie0ncrg"
}
},
"id": "7lqAYzwP92G9TMDBUVnadp",
"type": "Entry",
"createdAt": "2020-07-30T18:08:33.159Z",
"updatedAt": "2020-07-30T18:22:50.276Z",
"environment": {
"sys": {
"id": "master",
"type": "Link",
"linkType": "Environment"
}
},
"revision": 2,
"contentType": {
"sys": {
"type": "Link",
"linkType": "ContentType",
"id": "landingPage"
}
},
"locale": "en-US"
},
"fields": {
"pageTitle": "Leading the next generation of renewable fuels",
"heroImage": {
"sys": {
"type": "Link",
"linkType": "Asset",
"id": "vnjfnYzSyhqOjKlmNmBGb"
}
},
"pageZone": [
{
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "3aQvORUYowW0SoofuvHUov"
}
},
{
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "Qfj1hNJ9euSkBcAQEDaN5"
}
}
]
}
}"
I then parse the JSON:
let currentPage2 = JSON.parse(currentPage);
Now here's the issue. If log this in the console:
console.log(Object.keys(currentPage2.fields.pageZone[0].sys.id));
Node returns this in the terminal:
[
'0', '1', '2', '3', '4',
'5', '6', '7', '8', '9',
'10', '11', '12', '13', '14',
'15', '16', '17', '18', '19',
'20', '21'
]
I want to use this:
console.log(Object.keys(currentPage2.fields.pageZone[0].sys.id).value);
//with expected value of "3aQvORUYowW0SoofuvHUov"
Instead, it returns undefined. I have no idea why this is happening. I have tried using JSON.stringify etc and parsing it again, but it still behaves this way.
console.log(currentPage2.fields.pageZone[0].sys.id)