title: i var undefined inside a for loop
body: <pre><code>//Server Functions
  var socketArray = [];
  var socketRcon = [];
  for (var i = 0; i &lt; serversConfig.serversArray.length; i++) {
      socketArray[i] = new Socket;
      socketArray[i].setEncoding("utf8");
      socketArray[i].setNoDelay();
      socketArray[i].setTimeout(1000);
      socketArray[i].connect(serversConfig.serversArray[i].port, serversConfig.serversArray[i].ip);
      socketRcon[i] = serversConfig.serversArray[i].rcon;
      socketArray[i].on("connect", function() {
          this.write(socketRcon[i] + "\n", "utf8");
          console.log("CONNECTED TO THE SERVER...");
      });
      socketArray[i].on("data", function(data) {
          console.log(data);
      });
      socketArray[i].on("error", function(err) {
          console.log("ERROR:" + err);
      });
  
      socketArray[i].on("close", function(err) {
          console.log("CLOSED:" + err);
      });
  };
  </code></pre>
  
  <p>This is the code I have now to connect to multiple servers from a config file, and I need that each time the socket connects, I need to send a password to it. But 'socketRcon[i]' is undefined, why is that happening and how do i fix it?</p>