'having issues pushing object to array [duplicate]
Having issues with a simple push here, not understanding what is going on, I'm sure the answer is simple. Any advise here? Every time I log the array I'm trying to push to, it shows empty, however, the object that I am trying to push is loggable. Script is supposed to parse through a bunch of json files in order to combine and normalize the data inside. Using node.
const fs = require('fs');
let mergedobj = [];
const straindir = '../Strain Data/strains';
const terpdir = JSON.parse(fs.readFileSync('../Terpene Data/terp data.json'));
const cannadir = JSON.parse(fs.readFileSync('../Terpene Data/Cannabinoid Data.json'));
fs.readdir(straindir,(err,i)=>{
if(err){
console.log(err)
}
i.forEach(e =>{
const strainName = JSON.parse(fs.readFileSync(`../Strain Data/strains/${e}`))[0][1].toString();
let middleobj = {};
let j = 0;
cannadir.forEach( i=>{
if(i.tag === strainName){
middleobj[i.tag+' Cannabinoids '+ j] = i;
j++;
}
})
mergedobj.push(middleobj)
})
})
console.log(mergedobj)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
