It is best to use an array for this:
var test = []; for (i = 1; i <= countProjects; i++) { test[i] = $(otherVar).something(); };
Then you can access the following values:
console.log(test[1]); console.log(test[2]); etc...
If you have a good reason to have named variables for each value, you can create them as follows:
for (i = 1; i <= countProjects; i++) { window["test" + i] = $(otherVar).something(); }; console.log(test1);
source share