Find GameObjects with a true boolean and put them in an array?

I’m trying to place a bunch of similar gameobjects into an array that have the same true value as to be ‘active’.

Here is my code, which I understand why it is wrong, I’m trying to get a bool and put it into a gameobject array, not going to work, can’t figure out how to do this without doing a Gameobject.FindObjects with Tag, and make the other script put the box in the active tag whenever I do something, however that just seems cumbersome, any better ways?

public GameObject[] activeBoxArray;
public GameObject[] boxArray; // This is set to 7, and is the amount of boxes I normally have, when I click on them, the boxActive bool is set to true, and then I want to put that in the new array when the game is started by the player.

 if (Input.GetKey(KeyCode.Return))
    {
        for (int i = 0; i < boxArray.Length; i++)
		{
		activeBoxArray *= GameObject.Find("Box" + i.ToString()).GetComponent<BoxController>().boxActive == true;*
  •   	}*
    

}

using System.Linq;


activeBoxArray = FindObjectsOfType().Where(b => b.boxActive).Select(b => b.gameObject).ToArray();

A little bit of Linq and lambdas can do this in one line without any looping, string concatenation, or GetCompontent. This finds all the BoxControllers where boxActive is true, then we select the actual gameObjects rather than the BoxController component, and finally do a ToArray on our resultant set.

If you decide that:

 public GameObject[] activeBoxArray;

could actually just be:

 public BoxController[] activeBoxArray;

then you can remove the select query.