Javascript Array.prototype.filter() not working

前端 未结 1 1664
余生分开走
余生分开走 2020-11-27 23:05

I have this piece of code running on the client that filters a list of events:

if (res)
{
    eventList.filter(function(event) {

        const out = res.fin         


        
相关标签:
1条回答
  • 2020-11-27 23:40

    Array.prototype.filter does not change array inplace, it returns new array made of items that satisfies the provided predicate. It should look like this

    var result = eventList.filter(function(event) {
        return res.find(function(visibility) { return visibility.ID == event.id; }) === undefined;
    });
    

    You don't need to declare and assign variable and then return it from function, you can simply return expression

    0 讨论(0)
提交回复
热议问题