How to get the position of an instantiated object and store it in an array?

I’m working on a procedurally 2D path generation and my problem is that sometimes the path crosses itself and I don’t want that to happen.
As a solution to that, I wanted to get the x y coordinates of the rooms that are instantiated and store them in an array whenever a new room is instantiated and check if the new room position isn’t in that array. But I cannot find out how to do it. Can you please help me with this?

  1. How to get the position of instantiated object?
  2. How to store the positions in an array?

This is how you get the position from an instantiated object:

GameObject object = Instantiate(new GameObject());
Debug.Log(object.transform.position);