I want to remove array which is inside of whole array if an object of its array has certain value. I searched the web and I saw removing object or array if it has certain value and I can't find that solves my problem.
I have objects of array which is again wrapped by array. It looks like below:
"products": [
[
{
"product.name": "A",
"remark.name": "Good"
},
{
"product.name": "B",
"remark.name": "Good"
}
],
[
{
"product.name": "A",
"remark.name": "Bad"
},
{
"product.name": "B",
"remark.name": "Good"
}
]
]
What I want
I want to omit the whole array which contains at least remark.name === Bad
So, I should get the final result like below.
"products": [
[
{
"product.name": "A",
"remark.name": "Good"
},
{
"product.name": "B",
"remark.name": "Good"
}
]
]
What I've tried
Below code
let result = [];
products.map((product) => {
var res = _.remove(product, function (n) {
return n["remark.name"] === "Fail";
});
result.push(res);
});
produces following result:
"products": [
[
{
"product.name": "A",
"remark.name": "Good"
},
{
"product.name": "B",
"remark.name": "Good"
}
],
[
{
"product.name": "B",
"remark.name": "Good"
}
]
]