[Solved] Swift – Deleting a value in an array from an element


You can use filter to keep only the elements of the array whose age property doesn’t equal 10.

let filtered = array.filter { $0.age != "10" }

Unrelated to your question, but why is age a String? It should be an Int instead, since it represents a numeric value. Also, you should always make properties immutable (let) by default and only make them mutable (var) if they really need to be mutable.

1

solved Swift – Deleting a value in an array from an element