I have an array called burgerActions
:
[
{
statusId: 2,
label: 'Accept'
},
{
statusId: 3,
label: 'Reject'
},
{
label: 'Consult'
},
{
label: 'Transfer'
}
]
and also this object named status
which can be either :
{
"label": "Accept",
"id": 2
}
or :
{
"label": "Reject",
"id": 3
}
In the first scenario, a new array needs to be created from the burgerActions
array where the statusId
does not match the id of the status
object provided (we have only one status
object from the two cases listed).
To achieve this, the filter
method is utilized :
const result = burgerActions.filter((element) => {
return element.statusId !== recommendation.status.id
})
In the second scenario, a more complex condition needs to be applied alongside using boolean values
const statusRef = recommendation.recipient
In the first situation, I need to filter out the last object in the burgerAction
array ({label: 'Transfer'}
) if statusRef
is false, but not when it's true.
A method that accomplishes this type of filtering without direct if ()
conditions is required due to multiple scenarios being present.