Can i find an item in an array based on just a part of its name/ the end of its name?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By terazik_mubaloo

I need to look through the groups on an object (target) for if there’s one that ends with Floor, and then if there is, take its name and remove that Floor part. As seen in the code bellow, i have every part of that done except the part that finds that group in the array. Ive looked anywhere i could think of for a way to do so, but no result. Anyone know a solution? Also there wont be any objects with multiple groups ending in Floor so that doesnt need acounting for.

var ItemGroups = target.get_groups()
var ItemFloor = ItemGroups.find(~ending with "Floor"~)
var ItemHeld = ItemFloor.trim_suffix("Floor")

Could you iterate through the elements in the group, checking each element for the ending string?

for item in ItemGroups:
    if item is String and item.ends_with("Floor"):
        var ItemHeld = ItemFloor.trim_suffix("Floor")

Ertain | 2022-09-06 02:57

This worked, Thanks!

terazik_mubaloo | 2022-09-06 09:00