I am getting a following object
{
IuW1zvaSABwH4q: {
label: 'Random Image of TypeScript not relavent to coworking',
thumbId: 'd501-f-b601-c8b1-4bd995e',
schemaType: 'xman-assets-image-set'
}
}
Now, I want to access the value of thumbID inside it i.e. d501-f-b601-c8b1-4bd995e
But my root key seems to be dynamic/random (IuW1zvaSABwH4q), How can I access the value inside it?
An alternative way of using a combination of
JSON.stringify()
andsplit()
You can use
for..in
to iterate the object then check if this object has a key by namethumbId
. This check will ensure that code does not throw error if the object does not havethumbId
keyI use two nested for to extract the thumbId.
Assuming there is only one property you could access it via the first property.
You can use
Array.map
to transform it andArray.forEach
to get it and print it in the console.You can get the values from object and than access the desired key.