Load json once times


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) // return all the json file correctly

})

// how can avoid this as undefined

console.log(jsonCompleto) // return undefined

how can load only once the json file and use his all content in another things ?

put a = here and a return statement in the various chained functions

sorry, can you show me the code and explain me how to, can I load only once the json file, and use all the content file outside the function ?

You are only fetching the data once.

async and await can help you with your problem.

The code is not waiting for the fetch to return data and keeps on executing the next thing which is

and executes before the fetch gets the data so it logs undefined because it is well, yet undefined.