How to appoint ascending variables for every object in a group?

I have a group of objects with several objects inside. I want to make the first object’s variable to be 1, the second object in the group should get a variable 2, the third object should get a variable 3 and so on.

What are trying to do by doing that? There is likely a better way to achieve whatever you are trying to do than giving each object an “ID” number…