I am wondering why am I not able to get the array after I returned its values from the function? The output on the console is an empty array.
function fetchdates(){
let theDateTime,DatesSepTime,Dates = [];
fetch("./myfile.json")
.then((resp) => {
return resp.json();
})
.then((data) => {
for(let obj of data){
let theDateTime = obj.tweetcreatedts;
let DatesSepTime = theDateTime.split(" ");
let Dates = DatesSepTime[0];
//console.log(Dates);
}
})
return(Dates);
};
console.log(fetchdates());