JavaScript: Dynamically Creating Variables for Loops

You should use an array:

function createVariables(){
  var accounts = [];

  for (var i = 0; i <= 20; ++i) {
      accounts[i] = "whatever";
  }

  return accounts;
}

You then have access to accounts[0] through accounts[20].

Leave a Comment