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));