insert: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - "\] +\[" to "] [") |
m (Better explained format of array when using syntax 4) |
||
(One intermediate revision by one other user not shown) | |||
Line 21: | Line 21: | ||
|p3= valuesToInsert: [[Array]] of [[Anything]] - values to insert at the specified index | |p3= valuesToInsert: [[Array]] of [[Anything]] - values to insert at the specified index | ||
|p4= onlyIfUnique: [[Boolean]] - only insert if the value is unique in the array, like [[pushBackUnique]] | |p4= onlyIfUnique: [[Boolean]] - (Optional, default [[false]]) only insert if the value is unique in the array, like [[pushBackUnique]] | ||
|r1= [[Nothing]] | |r1= [[Nothing]] | ||
Line 57: | Line 57: | ||
|p63= keysAndValues: [[Array]] - in format depending on ''splitArray''<nowiki/>'s value: | |p63= keysAndValues: [[Array]] - in format depending on ''splitArray''<nowiki/>'s value: | ||
* [[true]] - {{hl|[<nowiki/>[key1, key2, ...], [value1, value2, ...]]}} | * [[true]] - {{hl|[<nowiki/>[key1, key2, ...], [value1, value2, ...]]}} | ||
* [[false]] - {{hl|[<nowiki/>[key1, value1], [key2, value2], ...]}} (same as {{Link|#Syntax 3}}) | * [[false]] - {{hl|[<nowiki/>[key1, value1], [key2, value2], ...]}} (same as {{Link|#Syntax 3}}, see {{Link|#Example 3}} for the correct format) | ||
|r4= [[Nothing]] | |r4= [[Nothing]] | ||
Line 76: | Line 76: | ||
private _array = ["a", "b", "c"]; | private _array = ["a", "b", "c"]; | ||
_array insert [-2, ["w"]]; // _array is now ["a", "b", "w", "c"] // Arma 3 v2.14 | _array insert [-2, ["w"]]; // _array is now ["a", "b", "w", "c"] // Arma 3 v2.14 | ||
</sqf> | |||
|x3= <sqf> | |||
// Notice how the size of the right array changes depending on the format of keysAndValues format | |||
private _map = createHashMap; | |||
_map insert [false, ["one", 1]]; | |||
private _map = createHashMap; | |||
_map insert [true, ["one"], [1]]; | |||
</sqf> | </sqf> | ||
Latest revision as of 11:41, 27 October 2024
Description
- Description:
- Inserts multiple values into Array/String/HashMap.
The String variant also supports forceUnicode. - Groups:
- HashMapArraysStrings
Syntax 1
- Syntax:
- array insert [index, valuesToInsert, onlyIfUnique]
- Parameters:
- array : Array
- index: Number - index at which the values will be inserted, -1 for append, 2.14 -2 for inserting at the second-to-last position, -3 before that, etc.
- valuesToInsert: Array of Anything - values to insert at the specified index
- onlyIfUnique: Boolean - (Optional, default false) only insert if the value is unique in the array, like pushBackUnique
- Return Value:
- Nothing
Syntax 2
- Syntax:
- string insert [index, substring]
- Parameters:
- string : String
- index: Number - index at which the values will be inserted, -1 for append
- substring: String - string to insert
- Return Value:
- String - the new string
Syntax 3
- Syntax:
- hashMap insert [[key1, value1], [key2, value2], ...]
- Parameters:
- hashMap: HashMap
- keyN: HashMapKey
- valueN: Anything
- Return Value:
- Nothing
Syntax 4
- Syntax:
- hashMap insert [splitArray, [keysAndValues]]
- Parameters:
- hashMap: HashMap
- splitArray: Boolean - determines keysAndValues format (see keysAndValues's description)
- keysAndValues: Array - in format depending on splitArray's value:
- Return Value:
- Nothing
Examples
- Example 1:
- "Test" insert [0, "Radio"]; // returns "RadioTest" "Test" insert [2, "Radio"]; // returns "TeRadiost" "Test" insert [-1, "Radio"]; // returns "TestRadio"
- Example 2:
- private _array = ["a", "b", "c"]; _array insert [0, ["w"]]; // _array is now ["w", "a", "b", "c"] private _array = ["a", "b", "c"]; _array insert [-1, ["w"]]; // _array is now ["a", "b", "c", "w"] private _array = ["a", "b", "c"]; _array insert [-2, ["w"]]; // _array is now ["a", "b", "w", "c"] // Arma 3 v2.14
- Example 3:
- // Notice how the size of the right array changes depending on the format of keysAndValues format private _map = createHashMap; _map insert [false, ["one", 1]]; private _map = createHashMap; _map insert [true, ["one"], [1]];
Additional Information
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