I am trying to delete the all the objects with _id "bennyRawMaterial" from below details array nested in the object:
let recipeBasicRecipes = [{
_id:'12345',
name:'Macaron Shell',
details:[
{
name: 'Sugar',
_id: 'bennyRawMaterial',
type: 'solid',
}
,
{
name: 'Egg white',
_id: '5fef680ca43301322a3224e5',
type: 'solid'
}]
},
{
_id:'14512345',
name:'Macaron Shell',
details:[{
name: 'Castiors gar',
_id: 'bennyRawMaterial',
type: 'solid'
},
{
name: 'oil',
_id: 'bennyRawMaterial',
type: 'solid',
}
, {
name: 'food',
_id: 'bennyRawMaterial',
type: 'solid',
}]
}]
I am using following code to remove the objects, but it skips few of the objects.Please help with the implementation
recipeBasicRecipes.forEach(br => {
br.details.forEach((rm, index) => {
if (rm._id === 'bennyRawMaterial') {
br.details.splice(index, 1);
} else {
return true;
}
});