rzh9b
rzh9b2y ago

adding async data to array?

i'm probably missing something obvious but i'm trying to add data that's async to an array in a forEach loop. below is my code:
const posts = await notion.databases.query({
database_id: Deno.env.get("DATABASE_ID"),
sorts: [
{
property: "Date",
direction: "descending"
}
]
})

const posts_array: Array<Record<string, unknown>> = [];

posts.results.forEach(async post => {
const title = post.properties.Title.title[0].text.content, date = post.properties.Date.date.start, id = post.id;
const content = await notion.blocks.children.list({ block_id: id, page_size: 100 });
const post_data = { title: title, date: date, content: content.results };
posts_array.push(post_data);
})
const posts = await notion.databases.query({
database_id: Deno.env.get("DATABASE_ID"),
sorts: [
{
property: "Date",
direction: "descending"
}
]
})

const posts_array: Array<Record<string, unknown>> = [];

posts.results.forEach(async post => {
const title = post.properties.Title.title[0].text.content, date = post.properties.Date.date.start, id = post.id;
const content = await notion.blocks.children.list({ block_id: id, page_size: 100 });
const post_data = { title: title, date: date, content: content.results };
posts_array.push(post_data);
})
apologies for the formatting
1 Reply
rzh9b
rzh9b2y ago
good idea thanks!