How can I change a parent of an object through script?

I want to change GameObjectX’s parent to something else. How can I go about this? Thanks!

GameObjectX.transform.parent = somethingElse.transform;

this is one of those questions that could be easily found on your own with a simple internet search…

questions like this have already been asked 100 times, so just search it, you’ll find lots of examples