您能告诉我如何使用lodash删除数组项列表吗?我已经尝试如下所示。但是它不起作用。
Video about the issue.
_.remove(previousNumberArray, (a) => {
_.some(this.removedQuestionCodes, (val, k) => {
return a.questionCode == val.questionCode;
});
});
最佳答案
问题是括号{}
{}
中的箭头功能应具有return
我们试试吧
_.remove(previousNumberArray, (a) => _.some(this.removedQuestionCodes, (val, k) => {
return a.questionCode == val;
}));
要么
_.remove(previousNumberArray, (a) => {
return _.some(this.removedQuestionCodes, (val, k) => {
return a.questionCode == val;
});
});
让我们看看我的例子:
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>
关于javascript - 删除数组项列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43961394/