cómo puedo usar el resultado de este enlace en javascript variable:
https://aa.real-tv1.com/testtt.php?action=reseller_mapdash1 let url = 'https://aa.real-tv1.com/testtt.php?action=reseller_mapdash1'; var myVariable; fetch(url).then(res => res.json()).then((out) => { myVariable = out; console.log([myVariable]); }).catch(err => { throw err }); console.log([myVariable]);entonces sé dónde está el problema ahora, cuando uso la variable 'myVariable'
fuera de una función tengo Variable indefinida
Entonces, ¿cómo puedo usar la variable fuera de una función?
Bueno, ha hecho la mayor parte del trabajo, simplemente asigna el resultado "fuera" a una variable como esta:
let url = 'https://aa.real-tv1.com/testtt.php?action=reseller_mapdash1'; let myVariable; fetch(url) .then(res => res.json()) .then((out) => { myVariable = out; // here you assign to your variable }) .catch(err => { throw err });