0

Currently I have a variable called "data" that I assign static JSON data, then push the values to arrays using three variables named rev_date, rev_area & rev_cases, using the following Javascript code;

data = [{
  "date": "2020-10-17",
  "areaName": "Devon",
  "newCasesByPublishDate": "108"
}, {
  "date": "2020-10-16",
  "areaName": "Devon",
  "newCasesByPublishDate": "76"
}];

let rev_date = [];
let rev_area = [];
let rev_cases = [];

data.map((item) => {
    rev_date.push(item.date);
    rev_area.push(item.areaName);
    rev_cases.push(item.newCasesByPublishDate);
  });

My question is, there is an api that returns the same data in JSON format, using the following URL - https://api.coronavirus.data.gov.uk/v1/data?filters=areaType=utla;areaName=devon&structure={"date":"date","areaName":"areaName","newCasesByPublishDate":"newCasesByPublishDate"}

Is there an easy way using ajax or something else to replace my static "data" variable holding the JSON data, to pull the data dynamically from the URL above?

Gary
  • 107
  • 10
  • 4
    *"Currently I have a variable called "data" that I assign static JSON data"* No, you assign it static **data** (specifically, an array of objects). JSON is a *textual notation* for data exchange. [(More here.)](http://stackoverflow.com/a/2904181/157247) If you're dealing with JavaScript source code, and not dealing with a *string*, you're not dealing with JSON. – T.J. Crowder Oct 18 '20 at 09:30
  • Read this along with the other linked posts: [How do I return the response from an asynchronous call?](https://stackoverflow.com/a/14220323/4642212). – Sebastian Simon Oct 18 '20 at 09:32

0 Answers0