I have a helper function(fetchData.js is the file name) which will send an array of json like this..
export const jsonData = async (file) => {
const response = await fetch(file);
const jsonData = await response.json();
return jsonData;
};
Now I want to utilize this helper in some other file ,
import { jsonData } from './fetchData.js';
jsonData('./data2.txt').then((data) => {
console.log(data);
});
and Its showing data perfectly, absolutely no issue..!!
But if I do something like this,
import { jsonData } from './fetchData.js';
let returnedData;
jsonData('./data2.txt').then((data) => {
returnedData = data;
});
console.log(returnedData);
it returns undefined..
How to do ?
Edit :