0

Can you tell me how to remove a list of array items using lodash? I have tried as shown below.But it is not working.

Video about the issue.

  _.remove(previousNumberArray, (a) => {

         _.some(this.removedQuestionCodes, (val, k) => {
            return a.questionCode == val.questionCode;
        });

   });
0

1 Answer 1

1

The problem is the bracket {} for arrow function inside {} should have return

Let's try

  _.remove(previousNumberArray, (a) => _.some(this.removedQuestionCodes, (val, k) => {
       return a.questionCode == val;
  }));

Or

  _.remove(previousNumberArray, (a) => {

         return _.some(this.removedQuestionCodes, (val, k) => {
            return a.questionCode == val;
        });

   });

Let's see my example:

var fruits1 = ['Apple', 'Banana', 'Orange', 'Celery'];

_.remove(fruits1, fruit => {//BRACKET
  //MUST HAVE RETURN KEYWORD
  return _.indexOf(['Apple', 'Banana', 'Orange'], fruit) !== -1
});

var fruits2 = ['Apple', 'Banana', 'Orange', 'Celery'];
_.remove(fruits2, fruit => {//BRACKET
  //DONT HAVE RETURN KEYWORD
  _.indexOf(['Apple', 'Banana', 'Orange'], fruit) !== -1
});

console.log('fruits1',fruits1)


console.log('fruits2', fruits2)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.6.1/lodash.js"></script>

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

3 Comments

Nope.None of above 2 solutions are working.Do you know why? It doesn't remove any item from the original array previousNumberArray.
So can you give an example of 2 arrays? I guess there are some problem with your _some
Glad to know that help :)

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.