How can I remove specific item from an array based on its name?

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

So basically I’m making a tower defense game and when an enemy enters an Aera2D I add it to an array but when he exists I want him to be removed from an array. As far as I know, since this is a smaller game performance shouldn’t be a problem so I think it should be fine. So basically how do I find and remove a specific item from an array based on its name?

:bust_in_silhouette: Reply From: djmick

You could do this:

for item in array:
     if item.name == "name":
     array.remove(item)

Just replace array with whatever your array is called, and “name” with whatever item you want to remove’s name.