当前位置:网站首页>Lodash filter collection using array of values

Lodash filter collection using array of values

2022-06-30 07:34:00 Superior virtue and weak water

problem :

I would like to filter a collection using array of property value. I want to use an array of attribute values to filter the collection .Given an array of IDs, return objects with matching IDs. Give a group ID, Return with matching ID The object of .Is there any shortcut method using lodash / underscore ? Is there any use of lodash / underscore Quick way ?

var collections = [{ id: 1, name: 'xyz' },                   { id: 2,  name: 'ds' },                   { id: 3,  name: 'rtrt' },                   { id: 4,  name: 'nhf' },                   { id: 5,  name: 'qwe' }];var ids = [1,3,4];// This works, but any better way?var filtered = _.select(collections, function(c){        return ids.indexOf(c.id) != -1});

Solution :

Reference resources : https://stackoom.com/en/question/1ANyG
原网站

版权声明
本文为[Superior virtue and weak water]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160540357780.html