February 2019
Beginner to intermediate
284 pages
6h 20m
English
Sometimes you need files from different sources that need to be loaded and then manipulated within a page. You load these using Promise.all(), as shown next. The code in the promise will only be executed when all the files are loaded (Examples/example-16.html):
const files = ['/path/to/file.json', '/path/to/file.csv']; var promises = files.map(file => fetch(file).then(resp => resp.text())); Promise.all(promises).then(results => { const jsonData = JSON.parse(results[0]); const csvData = Papa.parse(results[1], {header: true}).data; // use the two data objects });
Read now
Unlock full access