I need to alter each child object individually

So I’m trying to change the picture used for each button on a grid in an instantiated image prefab. The only way I can think of changing them will make them all the same but I want them all to be different. Any suggestions?

var children = transform.root.GetComponentsInChildren<Transform>();
        foreach (var child in children)
        {
            Debug.Log(child.name);
            if (child.name.Contains("XxX"))
            {
                child.GetComponent<Image>().sprite = newImage;
            }

            if (child.name.Contains("YyY"))
            {
                child.GetComponent<Text>().text = Convert.ToString(1);
            }
        }

Sidenote: each button has been named “XxX” and the text on each button was changed to “YyY”. This was done so as to prevent the code from changing the text and appearance of other buttons on the same page since the code effects EVERY child… if there’s a way around that I would like to learn as well, if I can do both with one change all the better.

Here is what i came up with

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

public class ChildFinder : MonoBehaviour
{
  public Sprite[] sprites;
  [HideInInspector]
  public Transform[] buttons, texts;

  void Start()
  {
    Transform[] children = transform.root.GetComponentsInChildren<Transform>();
    List<Transform> buttonsList = new List<Transform>();
    List<Transform> textList = new List<Transform>();
    foreach(Transform child in children)
    {
      if(child.GetComponent<Button>() != null)
      {
        buttonsList.Add(child);
      }
      else if(child.GetComponent<Text>() != null)
      {
        textList.Add(child);
      }
    }
    buttons = buttonsList.ToArray();
    texts = textList.ToArray();
    for(int i=0; i < buttons.Length; i++)
    {
      Transform button = buttons*;*

button.GetComponent().sprite = sprites*;*
}
for(int i=0; i < texts.Length; i++)
{
Transform text = texts*;*
text.GetComponent().text = “1”;
}
}
}
This script separates Buttons from text too and you don’t need to add XxX or YyY to their names, plus it gives the buttons distinct images from an array (it should have the same number of elements as there are buttons, or it’ll throw an index out of bounds error
…Hope this helps!