Get Sprite index in array by filename

I have a Sprite filled with 20 sprites. I want to change the current sprite of my gameobject by GetComponent().sprite = someSprite. I have the name (in a string) of the sprite I need to change to. There’s a built-in way to search in the Sprite array the sprite that’s name is the one I have? Something like Array.IndexOf(mySprites, nameImLookingFor); ?

You can use Array.FindIndex to search the array, and pass a predicate telling it what you are looking for. In this case you can do something like this:

int index = Array.FindIndex(spriteArray, s => s.name == nameImLookingFor);

This will either return the index of the sprite that matches the name, or -1 if it can’t find it.