I have thousands of legacy code that stores array information in a non array.
For example:
container.object1 = someobject;
container.object2 = someotherobject;
container.object3 = anotherone;
What I want to have is:
container.objects[1], container.objects[2], container.objects[3] etc.
The ‘object’ part of the name is constant. The number part is the position it should be in the array.
How do I do this?
Assuming that object1, object2, etc… are sequential (like an array), then you can just iterate through the container object and find all the sequential objectN properties that exist and add them to an array and stop the loop when one is missing.
If you want the first item
object1to be in the[1]spot instead of the more typical[0]spot in the array, then you need to put an empty object into the array’s zeroth slot to start with since your example doesn’t have anobject0item.