0

i wanted to work with fetched data out of its scope or assign the result into a variable but i cant always send a promise which its state is fullfiled and have result in it

   let fetchData = fetch("/some api /")
     .then(resposne => resposne.json())
     .then(data => data)
      console.log(fetchData)

the fetchData always is a promise witch with status of fullfiled how to i can use and work with data inside of last .then scope but not outside i tried to make a variable outside of it


      let someData;
      let fetchData = fetch("/some api /")
     .then(resposne => resposne.json())
     .then(data => {
      someData = data
      })
    console.log(someData)

but its undefined my question is how to work with fetched data and use it every where

guardian
  • 25
  • 5
  • 2
    Use [async/await](https://javascript.info/async-await). – kelsny Mar 20 '23 at 20:15
  • i did either but i still problem stays i did async function with await fetch and await response.json() and still cant access the data outsie and use them( i know its becuase of asynchrones behaviour i am access a promise before the fillfilment ) i tried alot of thing by searching nothing resolve the issue – guardian Mar 21 '23 at 01:05

0 Answers0