Если вы можете изменить функцию getData()
, чтобы иметь такой параметр, как getData(otherURL)
, вы можете сделать это:
function getOtherURL() {
const url = 'https://url/data.json';
fetch(url)
.then(res => res.json())
.then((data) => {
console.log('Checkout this JSON! ', data);
let otherURL;
for (let i = 0; i < data.length; i++) {
// some code
otherURL = `http://url/from${from}&to=${to}`;
}
console.log('otherURL', otherURL);
return otherURL;
})
.then(otherURL => {
// chain then() here
getData(otherURL);
})
.catch((err) => {
throw err;
});
}
Измененная функция
export function getData(otherURL) {
// need to read the value of otherURL and assign into new variable something like this
let newURL = otherURL;
console.log(newURL);
}