json file on server ('url') to read looks like this:
[{"name":"Belles, Josh", "rate":"1238", "id":"30091457"},
{"name":"Capwell, Thomas", "rate":"1956", "id":"16761815"},
{"name":"Craddock, Justin", "rate":"1587", "id":"14498573"}
]
function newFile(out) {alert(out); myArray = JSON.parse(out);}
// ALERT JUST SHOWS: [object Object],[object Object],[object Object],[object Object],[object Object]
fetch(url)
.then(res => res.json())
.then((out) => {
console.log('Output: ', out); // THIS WORKS
myArray = out; //WORKS
alert(myArray[1].name); //WORKS
console.log (JSON.stringify(myArray)); //WORKS
}).catch(err => console.error(err));
But any reference to myArray outside of the fetch doesn't see myArray.
Like this no longer works:
alert(myArray[1].name);
How can I use myArray outside of the fetch ?