lo siento, ¿alguien puede mostrarme el código y explicarme cómo puedo cargar solo una vez el archivo json y usar todo el archivo de contenido FUERA de la función?
let jsonCompleto fetch('uno.json') .then(function (response) { return response.json(); }) .then(function (data) { todo = data.length console.log(todo) jsonCompleto = data console.log(jsonCompleto) // this return all the json file correctly }) console.log(jsonCompleto) // this return undefined // how can load only once the json file and use all content of json file OUTSIDE the function ?puedes usar async/await
"use strict"; const myFetch = async () => { const response = await fetch('https://jsonplaceholder.typicode.com/posts/1') return response.json() } const myFunc = async () => { data = await myFetch() console.log(data) } myFunc()puede ver la documentación gratuita de recuperación