Why array argument is not visible in second then?
let assignDataToArray = (array) => {
fetch("data.json")
.then(response => {
if (response.ok)
return response.json();
else
throw new Error("Something went wrong with json file");
})
.then(result => array = [...result.data])
.catch(error => console.log(error));
}
let myArray = [];
assignDataToArray(myArray);
console.log(myArray);
I use VS Code and there is even pointed that array argument is not visible in scope of second then. In result the promise returns empty Array and nothing is assigned to array argument.