0

I am developing Node Js application using get-proxylist library so my question is how to get the value which is inside the function here is my code:

var proxylist = require('get-proxylist');
var array =[]
 proxylist(function(error, result){

        for(var i = 0; i < result.length; i++) {
            array.push(result[i]);
        }
    })
console.log(array[0]) // display undefined
devv
  • 67
  • 1
  • 6

1 Answers1

0

You're dealing here with asynchronous operations. At the timeconsole.log(array[0]) is executed, the callback passed to proxylist is not yet executed and array is still empty.

Faly
  • 13,291
  • 2
  • 19
  • 37