0

Instead of having the data array in the js-file I would like to read the "Object data" from an external file.

const object1 = {
        Day_1:89,
        Day_2:80,
        Day_3:78,
        Day_4:83,
        Day_5:89,
        Day_6:89,
        Day_7:80,
        Day_8:78,
        Day_9:78,
        Day10:83,
        Day11:89,
        Day12:80,
        Day13:78,
        Day14:83
};

for (const [key, value] of Object.entries(object1)) {
  console.log(`${key}: ${value}`);
}
001
  • 13,291
  • 5
  • 35
  • 66
Mizzy
  • 23
  • 5
  • Have you tried using `fetch`? – evolutionxbox Dec 20 '20 at 18:59
  • Have you considered to use JSON file ? it can be a good practise. let us know if you need help on that way – B.S. Dec 20 '20 at 19:08
  • let data = getText("fetch_info.txt"); async function getText(file) { let myObject = await fetch(file); for (const [key, value] of Object.entries(myObject)) { console.log(`${key}: ${value}`); } return myObject; } – Mizzy Dec 20 '20 at 19:46

0 Answers0