Filtering array with underscore.js

后端 未结 4 1854
囚心锁ツ
囚心锁ツ 2021-01-14 01:44

I am trying to filter some objects in my attempt to understand JS better and I\'m using underscore.js

I come from a C# background and am used to LINQ however undersc

4条回答
  •  太阳男子
    2021-01-14 01:47

    A more concise way to accomplish this would be with underscore's chain() function:

    var noMushrooms = _(products).chain()
        .filter(function (x) { 
            return !x.containsNuts;})
        .reject(function(x){ 
            return _(x.ingredients).any(function(y){
                return y === "mushrooms";
            });
        })
        .value();
    

提交回复
热议问题