remove(4);
The remove method returns true if an item is found matching the given criteria and false if it doesn ??™ t.
Therefore, it can be possible to repeat the search, if necessary, until false is returned and all items with
the given value are removed.
Splice()
The splice method allows the removal of multiple items in an Array. splice takes two parameters: the
starting location of the chunk to remove and the number of items in the chunk:
var chunk : Array < Int > = myArray.splice(2,2);
Once removed, the chunk of items is returned, which you can then store in a new Array, if you so want.
It is also possible to specify the starting location from the end of the Array using a negative number. In
such a case, the value of - 1 represents the last item in the Array, while decrementing that number will
count backward along the list of Array items:
var chunk : Array < Int > = myArray.splice(-2,2);
Here, the last two items in the Array were removed and stored in the Array chunk .
Inserting Values with Insert()
Inserting a value into the middle of an Array can be accomplished using the simple insert method.
Pages:
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123