How to pass a variable from a javascript function?

Good afternoon. Tell me how to get Listx of the design.
function name() {
 for (var i = 0; i < 9; i++){
yps.rot([jjjjjjj,gggggggg])
 .then(function (rot) {
 var Listx = rot.getLength()/1000;
 var List = rot.getLength()/1000+'<br>';
$('#list').append(List);
 }, function (error) {
 alert('error Occurred:' + error.message);
});
 alert(); //Here it should print the value of the Listx functions
}
}

How to withdraw Listx with the help of alert (for example)???
July 9th 19 at 10:45
1 answer
July 9th 19 at 10:47
Solution
Where your alert variable Listx yet, add another and then return to his listx:
function qwe(){
yps.root(data)
.then(function(){
 var promise = new Promise(function(s, e){
setTimeout(function(){
 // find listx
s(listx);
 }, 1000);
});
 return promise;
})
.then(function(listx){
 // do here what you need from listx
})
}
For asynchronous functions, this is not suitable... - Selena commented on July 9th 19 at 10:50
I've added a little magic to your response - aniya.Kertzmann65 commented on July 9th 19 at 10:53
Complex magic. For a sorcerer to such a low level as mine. Thank you. I will try and learn. - Selena commented on July 9th 19 at 10:56
: A Promise is essentially a class which allows you to make the request now, but to inform about the implementation later. root returns an instance of this class, and if you should also some kind of delay to make, you just need to return the same object .then understand that returned from the previous call and will either wait for "magic" or immediately executed. I advise you to read about the Promise, he is already becoming mainstream in the GS, soon to be if not the, then one of the leaders instead of kalbekov. - aniya.Kertzmann65 commented on July 9th 19 at 10:59

Find more questions by tags JavaScript