Reputation: 4610
How to get which do not intersect value between 2 Array with Lodash?
Expected:
const arr1 = [1, 2, 3]
const arr2 = [2, 3, 4]
console.log(unintersection(arr1, arr2))
Output
[1, 4]
Upvotes: 1
Views: 845
Reputation: 192607
Use _.xor()
to find the symmetric difference - the numbers that are in one of the arrays, but not both:
const arr1 = [1, 2, 3]
const arr2 = [2, 3, 4]
const result = _.xor(arr1, arr2)
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
Upvotes: 2