{"name":"insert","title":"insert","type":"command","url":"https://community.bistudio.com/wiki/insert","revid":377154,"updated":"2026-01-01T10:37:44Z","groups":["HashMap","Arrays","Strings"],"status":"ok","games":{"arma3":"2.02"},"since":"arma3 2.02","arma3_since":"2.02","description":"Inserts multiple values into Array/String/HashMap.\nThe String variant also supports forceUnicode. In the event of a HashMap, values, if they already exist, are replaced.","syntaxes":[{"syntax":"array insert [index, valuesToInsert, onlyIfUnique]","params":[{"name":"array","type":"Array of Anything","type_expr":"Array<Anything>","text":"array : Array of Anything"},{"name":"index","type":"Number","description":"index at which the values will be inserted, -1 for append, Arma 3 v2.14 -2 for inserting at the second-to-last position, -3 before that, etc.","type_expr":"Number"},{"name":"valuesToInsert","type":"Array of Anything","description":"values to insert at the specified index","type_expr":"Array<Anything>"},{"name":"onlyIfUnique","type":"Boolean","optional":true,"default":"false","description":"only insert if the value is unique in the array, like pushBackUnique","type_expr":"Boolean","text":"onlyIfUnique: Boolean - (Optional, default false) only insert if the value is unique in the array, like pushBackUnique"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"array"},"right":{"text":"[index, valuesToInsert, onlyIfUnique]"}},{"syntax":"string insert [index, substring]","params":[{"name":"string","type":"String","type_expr":"String","text":"string : String"},{"name":"index","type":"Number","description":"index at which the values will be inserted, -1 for append","type_expr":"Number"},{"name":"substring","type":"String","description":"string to insert","type_expr":"String"}],"returns":{"type":"String","type_expr":"String","description":"the new string"},"form":"binary","left":{"text":"string"},"right":{"text":"[index, substring]"}},{"syntax":"hashMap insert [[key1, value1], [key2, value2], ...]","since":"arma3 2.04","params":[{"name":"hashMap","type":"HashMap","type_expr":"HashMap"},{"name":"keyN","type":"HashMapKey","type_expr":"HashMapKey"},{"name":"valueN","type":"Anything","type_expr":"Anything"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"hashMap"},"right":{"text":"[[key1, value1], [key2, value2], ...]"}},{"syntax":"hashMap insert [splitArray, [keysAndValues]]","since":"arma3 2.04","params":[{"name":"hashMap","type":"HashMap","type_expr":"HashMap"},{"name":"splitArray","type":"Boolean","description":"determines *keysAndValues* format (see *keysAndValues*'s description)","type_expr":"Boolean"},{"name":"keysAndValues","type":"Array","description":"in format depending on *splitArray*'s value:\n\n- true - `[[key1, key2, ...], [value1, value2, ...]]`\n- false - `[[key1, value1], [key2, value2], ...]` (same as Syntax 3, see Example 3 for the correct format)","type_expr":"Array"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"hashMap"},"right":{"text":"[splitArray, [keysAndValues]]"}}],"examples":[{"text":"```sqf\n\"Test\" insert [0, \"Radio\"];        // returns \"RadioTest\"\n\"Test\" insert [2, \"Radio\"];        // returns \"TeRadiost\"\n\"Test\" insert [-1, \"Radio\"];    // returns \"TestRadio\"\n```","code":["\"Test\" insert [0, \"Radio\"];\t\t// returns \"RadioTest\"\n\"Test\" insert [2, \"Radio\"];\t\t// returns \"TeRadiost\"\n\"Test\" insert [-1, \"Radio\"];\t// returns \"TestRadio\""]},{"code":["private _array = [\"a\", \"b\", \"c\"];\n_array insert [0, [\"w\"]]; // _array is now [\"w\", \"a\", \"b\", \"c\"]\n\nprivate _array = [\"a\", \"b\", \"c\"];\n_array insert [-1, [\"w\"]]; // _array is now [\"a\", \"b\", \"c\", \"w\"]\n\nprivate _array = [\"a\", \"b\", \"c\"];\n_array insert [-2, [\"w\"]]; // _array is now [\"a\", \"b\", \"w\", \"c\"] // Arma 3 v2.14"]},{"code":["// Notice how the size of the right array changes depending on the format of keysAndValues format\nprivate _map = createHashMap;\n_map insert [false, [\"one\", 1]];\n\nprivate _map = createHashMap;\n_map insert [true, [\"one\"], [1]];"]}],"see_also":["HashMap","pushBack","pushBackUnique","append","+","merge"]}