Lodash union of arrays of mongoose ObjectId
If you're looking at two different arrays with strings of 'objectIDs' you can use concat
and then uniq
to remove the duplicates. Don't forget to run valueOf
at the end of your Lodash chain to call it to execute.
Below is an illustrative example:
let array1 = ['42142141221421d', '9999'];let array2 = ['s421421412412fef3', '42142141221421d', '1234'];const res = _(array1) .concat(array2) .uniq() .valueOf();console.log(res);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>