I want to know how can we remove some objects from the array using its key values?
For example in this code I am returning only the recettes which have this name "Lait de coco" but how can I remove from the array only the recettes which contain this string?
let result = recettes.filter(elt => {
return elt.ingredients.some(i => i.ingredient == "Lait de coco" )
})
console.log("result", result)
This is what I am trying but it is not working. Where could be the problem?
let result = recettes.filter(elt => {
return elt.ingredients.some(i => i.ingredient !== "Lait de coco" )
})
console.log("result", result)
This is my Array
const recipes = [
{
"id": 1,
"name" : "Limonade de Coco",
"servings" : 1,
"ingredients": [
{
"ingredient" : "Lait de coco",
"quantity" : 400,
"unit" : "ml"
},
{
"ingredient" : "Jus de citron",
"quantity" : 2
},
{
"ingredient" : "Crème de coco",
"quantity" : 2,
"unit" : "cuillères à soupe"
},
{
"ingredient" : "Sucre",
"quantity" : 30,
"unit" : "grammes"
},
{
"ingredient": "Glaçons"
}
],
"time": 10,
"description": "Mettre les glaçons à votre goût dans le blender, ajouter le lait, la crème de coco, le jus de 2 citrons et le sucre. Mixer jusqu'à avoir la consistence désirée",
"appliance": "Blender",
"ustensils": ["cuillère à soupe", "verres", "presse citron" ]
},
{
"id": 2,
"name" : "Poisson Cru à la tahitienne",
"servings": 2,
"ingredients": [
{
"ingredient" : "Thon Rouge (ou blanc)",
"quantity" : 200,
"unit" : "grammes"
},
{
"ingredient" : "Concombre",
"quantity" : 1
},
{
"ingredient" : "Tomate",
"quantity" : 2
},
{
"ingredient" : "Carotte",
"quantity" : 1
},
{
"ingredient" : "Citron Vert",
"quantity" : 5
},
{
"ingredient" : "Lait de coco",
"quantity" : 100,
"unit" : "ml"
}
],...