I am trying to be able to get value of the variable jsCss outside of the foreach and the readdir function. I can't seem figure it out. I tried to push it to a global variable but that still returned a empty array when I logged the array I pushed to. How would I go about doing this?
let items = [];
fs.readdir('.', (err, files) => {
const readable = files.filter((el) => /\.vide$/.test(el));
readable.forEach((script) => {
let data = fs.readFileSync(script, { encoding: 'utf8' });
const dom = htmlparser2.parseDOM(data);
const $ = cheerio.load(dom);
const CSS = $('Vide')
.clone()
.children()
.remove()
.end()
.text();
const str = css(CSS);
let jsCss = JSON.parse(str);
items.push(jsCss);
})
});
console.log(items)