Let's say I have 5 objects, box0 box1 box2 box3 box4 box5.
Is there any way to access their members in a for loop?
I tried this way, but it wouldn't work because box${i}is a string
let boxCoordinates: Array<Coordinate> = [];
for(let i=0;i<5;i++)
{
boxCoordinates.push(`box${i}`.current.getBoundingClientRect) //box0, box1, box2, box3, box4
}
Is there a reason to not have them all tracked in an array in the first place?
// Assuming their defined somewhere else
const boxArray = [box1, box2, box3, box4, box5];
for (let i =0; i < boxArray.length; i++ ) {
const box = boxArray[i];
// Do what you need with box now
}