相关疑难解决方法(0)

Javascript async function console log the returned data

How can I console log - or do any thing with the data returned from inside an async function?

example: JS FILE:

   async function getData(){
      try {
         $.getJSON('./data.json', (data) => {
            return data;
         });
      } catch(error) {
         console.log("error" + error);
      } finally {
         console.log('done');
      }
   }

   console.log(getData());
Run Code Online (Sandbox Code Playgroud)

JSON FILE:

{
   "stuff": {
      "First": {
         "FirstA": {
            "year": [2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017],
            "Categories": ["Suspension", "Electrical", "Performance", "Motor"]
         },
         "FirstB": {
            "year": [2007, 2008, 2009, …
Run Code Online (Sandbox Code Playgroud)

javascript json asynchronous return function

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

asynchronous ×1

function ×1

javascript ×1

json ×1

return ×1