Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have an array, say with 100 items in it, and I want to filter out all the items between 20-30.
Something like this, but this isn't correct obviously:
myArray.filter_by_indices(20...30)
I searched and searched, and couldn't find an answer.
array.removeSubrange(20...30)
You don't need a filter. You can simply call removeSubrange.
removeSubrange
myArray.removeSubrange(20..30)
And for the sake of completeness, here is an option using a filter:
myArray = myArray.enumerated().filter { $0.offset < 20 || $0.offset > 30 }.map { $0.element }
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
array.removeSubrange(20...30)?