(It's actually for an assignment)
Hi, For hours I tried to solve my problem, I found some solutions, but it wasn't really what I wanted, and from my code I'm always hitting the same wall. thank you.
So I have a JSON file and a javascript file :
In my JSON file I have simple array of list of URL
{
"myUrlDatabase":[
"https://www.francebleu.fr/emissions/ca-va-dans-le-bon-sens-en-poitou/poitou/quel-est-l-impact-du-changement-climatique-sur-les-migrations-d-oiseaux-marins",
"https://www.terrafemina.com/article/environnement-pourquoi-2021-est-une-annee-cruciale-pour-agir_a357981/1",
"https://www.franceinter.fr/monde/rechauffement-climatique-2020-est-l-annee-la-plus-chaude-jamais-enregistree-en-europe",
//more url
]}
I would like to access it in my javascript file, from what I have seen, I should use the fetch function, I followed a code on internet
fetch('/Data/url.json').then(function (response){
return response.json();
}).then(function (obj){
console.log(obj);
});
Indeed it print the file. but how can I make a var of the array ?
I would like later to use it in a random function
Math.randon() * {JSONFILE.length}