I'm trying to filter an array of objects by an object keys that have a value not empty
var collection = [
{
"season": "ETE 18",
"group": "GRBABY",
"market": "ALL",
"department": "ALL",
"skuType": "ALL",
"orderType": "ASE",
"packagingType": "CI"
},
{
"season": "ETE 18",
"group": "MEN",
"market": "ALL",
"department": "ALL",
"skuType": "ALL",
"orderType": "ASE",
"packagingType": "CI"
},
{
"season": "ETE 18",
"group": "GRBABY",
"market": "NONE",
"department": "ALL",
"skuType": "ALL",
"orderType": "ASE",
"packagingType": "CI"
},
]
var filterList = {season: "", group: "GRBABY", market: "ALL", department: "",
skuType: ""}
var result = _.filter(collection , proPack => {
if (filterList.group !== '') {
return proPack.group === filterList.group;
} else {
return proPack;
}
});
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
This works for me for one filter but I'm unable to find a way to filter for all other keys when they have a value.
the result shoud be :
result = [
{
"season": "ETE 18",
"group": "GRBABY",
"market": "ALL",
"department": "ALL",
"skuType": "ALL",
"orderType": "ASE",
"packagingType": "CI"
} ]