I need to push in array data if exist in array? Example code:
filterMealType(type){
this.filteredRecipe.map(
obj => {
if(obj.mealTypes.includes(type)){
this.filterRecipeByMealType.push(obj)
}else {
this.filterRecipeByMealType = []
}
}
)
console.log('current array ', this.filterRecipeByMealType)
}
type as parameter is only number, 0 or 1 or 2 or 3. filteredRecipe is array:
[
{
"name":"Obroki",
"description":"",
"difficulty":4,
"preparationTime":1920,
"ingredients":[
"dsad",
"dasdas"
],
"instructions":[
"sad",
"dsa"
],
"pictureUrl":"https://www.url.com/images/cb51adad61a04936b831378865ad8bf6.jpg",
"recepieType":"",
"mealTypes":[
0,
2
],
"id":281
},
{
"name":"Testen",
"description":"",
"difficulty":3,
"preparationTime":240,
"ingredients":[
"sestavino",
"test"
],
"instructions":[
"inst"
],
"pictureUrl":"https://www.url.com/images/aca27231f9af4ed0af5e1ec4af09861e.jpg",
"recepieType":"",
"mealTypes":[
0,
2
],
"id":282
},
{
"name":"Mleko",
"description":"",
"difficulty":2,
"preparationTime":2580,
"ingredients":[
"ddd"
],
"instructions":[
"das",
"dasd"
],
"pictureUrl":"https://www.url.com/images/1fd0bd88175a4680ae9430579f1b781c.jpg",
"recepieType":"",
"mealTypes":[
1
],
"id":283
},
{
"name":"test",
"description":"",
"difficulty":4,
"preparationTime":240,
"ingredients":[
"jajca",
"meso"
],
"instructions":[
"rf"
],
"pictureUrl":"https://www.url.com/images/0fafcd552354468bbca3a78cb9796004.jpg",
"recepieType":"",
"mealTypes":[
0,
2
],
"id":211
}
]
I if obj.mealTypes includes any of number i need to push to array. Right now no work good. Now i only push one item...no work good. If you need i can share to stackblitz