Description
Intersects two arrays returning an array of unique common elements, avoiding nil values.
Using the same array as both parameters will return unique elements of that array.
Intersects only the first dimension of said arrays.
Note
From Arma 3 v 2.14 the order of the intersected elements would follow 'array1' order
Syntax
array1 arrayIntersect array2
Parameters:
Returns: Array of Anything
Examples
Example 1
_arr1 = [1,2,3,4,5,2,3,4];
_arr2 = [4,5,6,1,2,3,5,6];
hint str (_arr1 arrayIntersect _arr2);
Example 2
_arr = [1,2,3,1,2,3,1,2,3,4,5];
hint str (_arr arrayIntersect _arr);
Example 3
Remove nils:
hint str ([1,2,nil,3] arrayIntersect [1,2,nil,3]);
Example 4
Also works with array elements which are equal:
hint str ([[1],[2],[3]] arrayIntersect [[2],[3],[4]]);
Example 5
This command is case-sensitive:
["cAse"] arrayIntersect ["cAse"];
["cAse"] arrayIntersect ["casE"];
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
Selectively filter out elements from _arrayA based on _arrayB.
- Designed to remove the first occurrence of each element found in _arrayB from _arrayA.
- Useful in removing elements where duplicates may exist.
private _arrayA = [1, 2, 3, 2, 4, 5, 4];
private _arrayB = [2, 2, 4];
{
private _index = _arrayA find _x;
if (_index != -1) then
{
_arrayA deleteAt _index;
};
} forEach _arrayB;
_arrayA;