Both the index and key for each property_name from a database query are dynamic. The only constant is the type: "title" for the title property. The title itself is also nested in an array. I've marked it as I NEED THIS in the schema below. Furthermore, only one property is type: "title".
I have tried just about every object and array prototype function in various combinations , but due to the nested objects and arrays, and the property_name index and key being unknown, I cant figure it out.
My desired result would be to obj.map() the plain_text title and page_id of each page in the result to a JSX object.
Schema:
{
object
results [
{
object: page
page_id: 442k3j423j4hk23kjh423
created_time
last_edited
parent {
type
database_id
}
archived
url
properties {
property_name {
id
type: 'title'
title [
plain_text: 'I NEED THIS'
id
]
}
property_name {
id
type
}
property_name {
id
type
}
}
},
{
object: page
id
created_time
last_edited
parent {
type
database_id
}
archived
url
properties {
property_name {
id
type
}
property_name {
id
type
}
property_name {
id
type
}
}
},
]
}
Desired resulting object for mapping:
var pages {
page1: {
page_id: '23j4lk23j4lk23j',
page_title: 'This is a title'
}
page1: {
page_id: '23j4lk23j4lk23j',
page_title: 'This is a title'
}
}