{"name":"arrayIntersect","operator":null,"title":"arrayIntersect","type":"command","url":"https://community.bistudio.com/wiki/arrayIntersect","revid":377192,"updated":"2026-01-01T10:54:34Z","groups":["Arrays"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.48"}],"since":{"game":"arma3","name":"Arma 3","version":"1.48"},"arma3_since":"1.48","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Intersects two arrays returning an array of unique common elements, avoiding nil values.\nUsing the same array as both parameters will return unique elements of that array.\nIntersects only the first dimension of said arrays.\n\n> [!NOTE]\n> From Arma 3 v 2.14 the order of the intersected elements would follow 'array1' order","syntaxes":[{"syntax":"array1 arrayIntersect array2","since":null,"effect":null,"exec":null,"params":[{"name":"array1","type":"Array of Anything","optional":false,"default":null,"description":null,"types":["Array","Anything"],"since":null,"text":"array1: Array of Anything"},{"name":"array2","type":"Array of Anything","optional":false,"default":null,"description":null,"types":["Array","Anything"],"since":null,"text":"array2: Array of Anything"}],"returns":{"type":"Array of Anything","types":["Array","Anything"],"description":null,"text":"Array of Anything"},"form":"binary","operator":null,"left":{"text":"array1","types":["Array","Anything"]},"right":{"text":"array2","types":["Array","Anything"]}}],"examples":[{"text":"```sqf\n_arr1 = [1,2,3,4,5,2,3,4];\n_arr2 = [4,5,6,1,2,3,5,6];\nhint str (_arr1 arrayIntersect _arr2); // [4,5,1,2,3]\n```","code":["_arr1 = [1,2,3,4,5,2,3,4];\n_arr2 = [4,5,6,1,2,3,5,6];\nhint str (_arr1 arrayIntersect _arr2); // [4,5,1,2,3]"]},{"text":"```sqf\n_arr = [1,2,3,1,2,3,1,2,3,4,5];\nhint str (_arr arrayIntersect _arr); // [1,2,3,4,5]\n```","code":["_arr = [1,2,3,1,2,3,1,2,3,4,5];\nhint str (_arr arrayIntersect _arr); // [1,2,3,4,5]"]},{"text":"Remove nils:\n\n```sqf\nhint str ([1,2,nil,3] arrayIntersect [1,2,nil,3]); // [1,2,3]\n```","code":["hint str ([1,2,nil,3] arrayIntersect [1,2,nil,3]); // [1,2,3]"]},{"text":"Also works with array elements which are equal:\n\n```sqf\nhint str ([[1],[2],[3]] arrayIntersect [[2],[3],[4]]); // [[2],[3]]\n```","code":["hint str ([[1],[2],[3]] arrayIntersect [[2],[3],[4]]); // [[2],[3]]"]},{"text":"This command is case-sensitive:\n\n```sqf\n[\"cAse\"] arrayIntersect [\"cAse\"]; // [\"cAse\"]\n[\"cAse\"] arrayIntersect [\"casE\"]; // []\n```","code":["[\"cAse\"] arrayIntersect [\"cAse\"]; // [\"cAse\"]\n[\"cAse\"] arrayIntersect [\"casE\"]; // []"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["append","set","pushBack","pushBackUnique","apply","select","resize","reverse","count","find","in","forEach","deleteAt","deleteRange","sort","param","params","toArray","toString","splitString","joinString","BIS_fnc_arrayPushStack","BIS_fnc_arrayPush"],"notes":[{"user":"Hypoxic125","date":"2024-05-26T16:50:02Z","text":"Selectively filter out elements from _arrayA based on _arrayB.\n- Designed to remove the first occurrence of each element found in _arrayB from _arrayA.\n- Useful in removing elements where duplicates may exist.\n\n```sqf\nprivate _arrayA = [1, 2, 3, 2, 4, 5, 4];\nprivate _arrayB = [2, 2, 4];\n\n{\n    private _index = _arrayA find _x;\n    if (_index != -1) then\n    {\n        _arrayA deleteAt _index;\n    };\n} forEach _arrayB;\n\n_arrayA; // is now [1, 3, 5, 4]\n```"}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Arrays","Introduced with Arma 3 version 1.48","Scripting Commands"]}