0

Consider following arrays:

array1 = ['a','b'];
array2 = ['a','b','c','d'];

I need to extract the difference. So my resulting array should look something like,

array3 = ['c','d'];

If an element is present in array1 then it should be poped from array2. I am looking for solutions more angular way,is there any directive available?

2

1 Answer 1

1

In my opinion you can use underscore or lodash library for such tasks. for example in underscore you can done it through this simple code :

difference_.difference(array, *others)

Similar to without, but returns the values from array that are not present in the other arrays.

_.difference([1, 2, 3, 4, 5], [5, 2, 10]); => [1, 3, 4]

underscore annotated source

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.