Loading multiple files

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
});
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset