How to remove items from a array while iterating in Julia?

Viewed 155

I am trying to iterate through an array (or tuple, etc.) and want to remove certain items if they meet my criteria. The output could a modified array or a new array altogether if I can't modify the existing object I am iterating through.

for item in simple_array
    if some_condition
       add_to_new_array(item) # or remove from my existing array
    end
end
1 Answers

You could use filter , or if you want to modify the existing array use filter! instead.


filter(isodd, simple_array)

Related