unable to access array outside an async function

Viewed 21

demo.json content ["2018-06-01",2018-07-01","2018-08-01", "2018-09-01","2018-10-01", "2018-11-01"]

i am trying to parse a local json file and populate an existing array but unable to access the populated array outside the async function

arr1=[];
jsonurl = 'demo.json';

async function fetchdata() {
    res = await fetch(jsonurl);
    arr1= (await res.json());
    console.log(arr1); //<== this returns a populated array
}
fetchdata();

console.log(arr1);//<== this returns a empty array
0 Answers
Related