stevemcilwaine
6/5/2019 - 1:42 PM

Using fetch to get external json and push to array

Using the new fetch function to get data from url, convert to json and then use a spread (...) to push results into an array arr.

const url = "https://jsonplaceholder.typicode.com/todos";
const arr = [];
fetch(url)
  .then(response => response.json())
  .then(json => arr.push(...json));