var myids = '';
function passid(){
onload = function () {
uidt = tempid.ssid; // some value getting from API
}
}
passid();
console.log(myids);
Can Anyone help me with this, How to push uitd to var myids so I can be use wherever I want.
Your API request is definitely asynchronous, so you can use the promises via async await if you are inside an asynchronous function or then and catche if you are outside an asynchronous function
var mydata = '';
async function apiReq(){
return await fetch('https://jsonplaceholder.typicode.com/todos/1').then(response=>response.json()).then(response=>{
mydata = response
console.log("test");
console.log(mydata);
})
}
apiReq().then(response => {
console.log("request is ok")
console.log(mydata);
});