check where a game object is in an array

I have an array of GameObjects and I have a GameObject variable how do I check what number the GameObject variable is in the array?

If it’s a built-in array (GameObject), the only way I know is to compare each element like this:

var goArray: GameObject[];

function ObjectIndex(myObj: GameObject): int {
  for (var ix = 0; ix < goArray.lenght; ix++){
    if (goArray[ix] == myObj) return ix;
  return -1;

This function will return the object index, or -1 if not found.