Skip to content

arrDifference

Returns the values of the first array that are not contained in any of the other arrays.

The original order is preserved and duplicates of a kept value are not removed, so arrDifference([2, 1, 2, 3], [1]) returns [2, 2, 3].

Values are compared by value, not by reference, so nested arrays and objects are matched as well: arrDifference([[1], [2]], [[1]]) returns [[2]]. Types are not coerced — 1 and '1' are different values.

The arrays to subtract are passed as additional arguments.

The arrays to subtract are passed as a single list of lists.

Parameters

NameTypeRequiredDefault
arrayany[]List<dynamic>list[Any]
The array to inspect. It is not modified.
othersany[][]List<List<dynamic>>list[list[Any]]
The arrays whose values are excluded. Omit them to get a copy of array.

Returns

any[]

List<dynamic>

list[Any]

Examples

javascript
arrDifference([2, 1, 3], [2, 3]); // Returns [1]
arrDifference([2, 1, 2, 3], [1]); // Returns [2, 2, 3]
arrDifference([1, 2, 3, 4], [2], [4]); // Returns [1, 3]
arrDifference([[1], [2]], [[1]]); // Returns [[2]]
arrDifference([1, '1'], [1]); // Returns ['1']
dart
arrDifference([2, 1, 3], [[2, 3]]); // Returns [1]
arrDifference([2, 1, 2, 3], [[1]]); // Returns [2, 2, 3]
arrDifference([1, 2, 3, 4], [[2], [4]]); // Returns [1, 3]
arrDifference([[1], [2]], [[[1]]]); // Returns [[2]]
arrDifference([1, '1'], [[1]]); // Returns ['1']
python
arrDifference([2, 1, 3], [2, 3])  # Returns [1]
arrDifference([2, 1, 2, 3], [1])  # Returns [2, 2, 3]
arrDifference([1, 2, 3, 4], [2], [4])  # Returns [1, 3]
arrDifference([[1], [2]], [[1]])  # Returns [[2]]
arrDifference([1, '1'], [1])  # Returns ['1']

Released under the MIT License