Access to global variables modified in a function from different files

I am using webpack and I have 2 global variables, I assign them in a function and I want to use them in another function in another file. Is that possible? my code:

var info = []; async function getSearch(searchBar) {        try {            const value = (document.getElementById(searchBar).value).toLowerCase();            const url = `http://api.openweathermap.org/data/2.5/weather?q=${value}&APPID=1&units=metric`;            const url2 = `http://api.openweathermap.org/data/2.5/weather?q=${value}&APPID=1&units=imperial`;            const response = await fetch(url, { mode: 'cors' });            const response2 = await fetch(url2, { mode: 'cors' });            cityData = await response.json();            cityData2 = await response2.json();            info = [cityData, cityData2];        } catch (error) {            console.error('Error:', error);        }    };  function getInfo(){  return info; }  

I export both variables (cityData and cityData2) to use them into another function in another file but got the error ‘variable not defined’. How can I do to access the data wherever I want? Thanks

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.