I am declaring an array list_of_blogposts
and then I am opening a file to pull data from it, and in it, I am declaring an object blogpost_object
in which I am entering key-value pairs. When I console log it inside the opened file code block it does console log properly, but outside it, it shows empty, like in the last line it doesn't work. Can anybody mention whats the reason and solution for it? Thanks, the code is below
const list_of_blogposts = [];
new XLSX()
.extract("./all_blogposts.xlsx", {
ignore_header: 2,
include_empty_rows: false,
sheet_name: "all_blogposts"
})
.on("row", function(row) {
var blogpost_object = {};
blogpost_object["title"] = row[2];
list_of_blogposts.push(blogpost_object);
console.log(list_of_blogposts);
});
console.log(list_of_blogposts);