0

My function:

async function GetItemStats(item_id) {
  var jsonResponse;
  const url = "someUrl";
  const data = { data: item_id };
  const options = {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Cookie:
        "cookie"
    },
    body: JSON.stringify(data)
  };
  await fetch(url, options)
    .then(res => {
      jsonResponse = res.json();
      return jsonResponse;
    })
    .then(json => {
      console.log(json); //I can see the correct json
    });
}

But when i try to call it:

var getItem = GetItemStats("Police_cap").then(function(result) {
  console.log(result); //undefined 
});

Console:

-Correct Json-

-undefined-

Why is it returning it undefined when i can see the full json when i execute the function, but can't seem to work if i try to return the value.

0 Answers0