Uland Nimblehoof
Uland Nimblehoof

Reputation: 1032

Lodash - method which return non-share elements from two arrays

Helo guys, could you help with:

I need a method to lodash which return:

_.method( [1,2,3,4,5,6,7], [1,2,3] ) => [4,5,6,7]

In other words method which return non-share elements.

Best regards Greg.

Upvotes: 2

Views: 41

Answers (2)

Uland Nimblehoof
Uland Nimblehoof

Reputation: 1032

I found:

For Objects it should be:

albumNotPhotos = _.differenceWith(this.albumNotPhotos, this.albumPhotos, _.isEqual);

Thanks and regards!@

Upvotes: 0

Nina Scholz
Nina Scholz

Reputation: 386634

You could use _.difference.

Creates an array of array values not included in the other given arrays using SameValueZero for equality comparisons. The order and references of result values are determined by the first array.

var result = _.difference([1, 2, 3, 4, 5, 6, 7], [1, 2, 3]);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>

Upvotes: 3

Related Questions