deleteAt: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) No edit summary |
Killzone Kid (talk | contribs) (Undo revision 347784 by killzone_kid (talk)) Tag: Undo |
||
Line 17: | Line 17: | ||
|p2= index: [[Number]] or {{GVI|arma3|2.16|size= 0.75}} [[Array]] in format [index], where index is a single positive, zero or negative [[Number]] (see a note in description) | |p2= index: [[Number]] or {{GVI|arma3|2.16|size= 0.75}} [[Array]] in format [index], where index is a single positive, zero or negative [[Number]] (see a note in description) | ||
|r1= [[Anything]] - returns the deleted element | |r1= [[Anything]] - returns the deleted element | ||
|s2= hashMap [[deleteAt]] key | |s2= hashMap [[deleteAt]] key |
Revision as of 09:10, 26 October 2023
Description
- Description:
- Removes array element at the given index and returns removed element (modifies the original array, just like resize or set).
- Groups:
- ArraysHashMap
Syntax
- Syntax:
- array deleteAt index
- Parameters:
- array: Array
- index: Number or 2.16 Array in format [index], where index is a single positive, zero or negative Number (see a note in description)
- Return Value:
- Anything - returns the deleted element
Alternative Syntax
- Syntax:
- hashMap deleteAt key
- Parameters:
- hashMap: HashMap
- key: HashMapKey
- Return Value:
- Anything
Examples
- Example 1:
- Example 2:
- Example 3:
- Example 4:
Additional Information
- See also:
- deleteRange set resize select in find findIf toArray toString forEach count pushBack pushBackUnique apply append sort param params arrayIntersect splitString joinString
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Oct 15, 2014 - 16:55 (UTC)
-
is almost 60x faster than (Tested with an array of 10.000 strings, iterating through it using a for-from-to-do loop)_array deleteAt 0;
- Posted on Mar 04, 2016 - 15:58 (UTC)
- Deleting from an array with foreach and _foreachIndex variable is tricky. The array is being altered, the _foreachIndex won't keep up and other elements in the array will be skipped and in worst case not being deleted. If you delete elements from an array in descending order (using while or for) it will work.
- Posted on Feb 09, 2017 - 22:45 (UTC)
- To expand on Highheads comment above - this is because forEach implements iterators to traverse a collection, which are read only by definition. The variable _x is an iterator that points to the current item in the collection. Trying to alter _x will have no effect. When trying to use deleteAt inside forEach, the behaviour would be undefined as you are invalidating the iterator reference, and it will not know how to traverse to the next element. In short, only use forEach when reading data from an array. For more info about iterators, see C++ Iterators.
- Posted on Feb 01, 2021 - 18:06 (UTC)
-
As you would expect from a simple array implementation,
is virtually zero cost (0.0005ms on an array of 1000000 elements), while
is very performance heavy (0.7ms on the same huge array).array deleteAt 0;