I am not sure if this is possible, but I want to create a multiple vars dynamically, for instance, these are the vars I create manually,
var left_1 = $('.column-global.left .item-global').eq(0);
var left_2 = $('.column-global.left .item-global').eq(1);
var left_3 = $('.column-global.left .item-global').eq(2);
but the problem is I only need two or one vars above sometimes. but three is the max.
so I am thinking of passing a parameter into the function to tell the code to create either 2 or 3 vars,
// I declare empty vars first
var left_1;
var left_2;
var left_3;
// get the number from somewhere, from the class for instnace
var last_class = $(this).attr("class").split(' ').slice(-1);
// loop the number with for loop
for( var i = 1; i <= last_class; i++){
left_1 = $('.column-global.left .item-global').eq(i-1);
}
but you notice that I am stuck - how can I loop the var in the {} of the for-loop?
basically I want the for loop to produce the multiple vars like these (same as above),
var left_1 = $('.column-global.left .item-global').eq(0);
var left_2 = $('.column-global.left .item-global').eq(1);
var left_3 = $('.column-global.left .item-global').eq(2);
is it possible??
thanks.
p.s.
some answers here suggesting an array, but I have another problem further...
bcos I also need to pass the vars into another function which is kept within that parent function like this,
another_function(left_1, left_2, left_3);
so how can I achieve this with the array?? thanks