I have two arrays created outside a method:
let titles1 = [];
var checked1 = [];
async function fetchPosts(titles, checked) {
try {
const rawPosts = await fetch("......");
const posts = await rawPosts.json()
for (var i = 0; i < posts.length; i++) {
titles.push(posts[i]["title"]);
checked.push(posts[i]["checked"]);
}
return posts
} catch (e) {
console.log("error on getting data: ", e)
}
}
fetchPosts(titles1, checked1);
console.log(titles1[0])
so the method fetchPosts populates both arrays. However when I do a console log on titles1 and checked1, there is nothing. How can I populate them?