& b outside of fetch api ?
fetch( url ) .then((response) => { if(response.ok){ return response.text(); } }) .then((text) => { var a = ( text.split(',')[18] ).split(';')[1] ; var b = ( text.split(',')[23] ) ; })
since you are using var, I think you can use it outside of the fetch. But before using them you should wait for the execution of the fetch. When fetch executed completely you can use them before exec it will give undefined most probably
no i can for example this has error a is undefined
fetch( url ) .then((response) => { if(response.ok){ return response.text(); } }) .then((text) => { var a = ( text.split(',')[18] ).split(';')[1] ; var b = ( text.split(',')[23] ) ; }) console.log(a)
const run = async() => { const res = await fetch(url); const data = await response.text(); const a = ....; const b = ....; console.log(a, b) } run();
Обсуждают сегодня