Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

save data response from fetch as global param js

let dataGlobal;

const getData = async () => {
  const response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
  const data = await response.json();
  dataGlobal = data;
  return data;
};

(async () => {
  await getData();
  console.log(dataGlobal);
})();
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #save #data #response #fetch #global #param #js
ADD COMMENT
Topic
Name
6+4 =