I'm currently stuck trying to access a JSON file called map.json using fetch(). Here's my code snippet:
export function importJSON(url) {
return fetch(url)
.then(r => r.json())
.then(data => {
return data;
});
}
Then I assign the result of the function call to a variable named json and log it to the console:
const json = importJSON('../src/JSON/map.json');
console.log(json);
However, when I log it, instead of displaying the actual JSON content, it shows a Promise with [[PromiseResult]] that contains the JSON data. But I'm unsure how to access it properly:
Promise {<pending>}
__proto__: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Object
map: {platform: {…}}
__proto__: Object
Beneath the Promise section is the actual JSON (including map and platform keys/values). How can I correctly access this JSON data?