While attempting to follow a tutorial on YouTube, I encountered an issue where the code didn't work as expected. Can anyone lend a hand in helping me figure out what might be going wrong?
let posts = [
{name: '1', data: 'Hi1'},
{name: '2', data: 'Hi2'},
]
function getPosts() {
setTimeout(()=> {
posts.forEach((post) => {
console.log(post.name)
})
}, 1000)
}
function createPost(post) {
setTimeout(()=> {
posts.push(post)
}, 2000)
}
async function init() {
await createPost({name: '3', data: 'hey'})
getPosts()
}
init();