R
R
Rabinzon2015-11-15 18:11:08
JavaScript
Rabinzon, 2015-11-15 18:11:08

Accessing data outside of an async function?

I need access to the data array outside of someFun, outside of the loop.
How to get out?

var data = [];

while(i<10)
{
  someFun(i, function(array){
    data[i] = array[i]; 
  });
  
  i++;		
}
console.log(data[0])

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav Lyzlov, 2015-11-15
@dixoNich

What is hardcore? Why do an asynchronous operation in a loop?
https://developer.mozilla.org/en/docs/Web/JavaScri...
Use this to make your life better.

N
Nicholas, 2015-11-17
@ACCNCC

Here is a Promise with node and browser support to boot
bluebirdjs.com/docs/getting-started.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question