Array Remove element

From SwiftAPI

Jump to: navigation, search

Remove all instances of an element from an array. Also see Array Remove for removing only the first instance.

C++

#include <vector>
#include <string>
#include <algorithm>
using namespace std;
 
string values[] = {"a", "b", "c", "a", "b"};
vector<string> arr(values, values+5);
arr.erase(remove(arr.begin(), arr.end(), string("b")), arr.end());
// arr == ["a", "c", "a"]

Objective-C

developer.apple.com

- (void)removeObject:(id)anObject
NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"a", @"b", @"c", @"a", @"b", nil];
[arr removeObject:@"b"];
// arr == [@"a", @"c", @"a"]

Ruby

Ruby-Doc.org

arr = ["a", "b", "c", "a", "b"]
arr.delete("b")
# arr => ["a", "c", "a"]
Personal tools