1

Hi I'm trying to get JSON data from a JSON file. I got it on my JS code but i cant use it out of the callback function. I want to use the data anywhere in my code. I want to pass the data to a variable

My code for getting JSON data is :

async function load() {
    let url = 'sorular.json';
    let obj;
    obj = await (await fetch(url)).json();
    return obj
}
    load().then(res=>{console.log(res)})
Eren Talan
  • 13
  • 3

1 Answers1

0

in the THEN, simply call a separate function where res is passed as argument.

function processJSON(data){
  //run your other functions here
}

load().then(res=>{processJSON(res)})
imvain2
  • 15,480
  • 1
  • 16
  • 21