I'm trying to assign var globally but getting "undefined". How should I assign a variable in order to get the address outside the jsonReader ?
When I checked log inside jsonReader it works fine but when I'm trying to assign it to a gloabl var it shows undefined.
var myaddress;
jsonReader('./data.json',(error,data)=>{
if(error){
console.log(error);
}else{
addresses = data.records.map(record => record.data.property_name);
addresses.forEach(element => {
myaddress = element;
console.log(myaddress);
});
}
})
doc.render({
propertyname: myaddress,
propetytype: "",
phone: "",
description: "New Website",
});
data.json:
{
"name": "test",
"records": [
{
"position": 1,
"data": {
"employees": {
"teams": [],
"users": []
},
"address": "ABC 123 Street"
}
},
{
"position": 2,
"data": {
"employees": {
"teams": [],
"users": []
},
"address": "DEF 456 Street"
}
}
]
}