Reputation: 65900
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.
_.remove(previousNumberArray, (a) => {
_.some(this.removedQuestionCodes, (val, k) => {
return a.questionCode == val.questionCode;
});
});
Upvotes: 0
Views: 70
Reputation: 2776
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>
Upvotes: 1