I need to remove an nested array if it matches the id of the main array.
arrayOne =
[
{
"id": "1",
"role": [
"pos_cashier_1",
"pos_manager"
]
},
{
"id": "2",
"role": [
"pos_manager",
"pos_cashier_2"
]
}
]
arrayTwo
[
{
"label": "Sessions Sandringham",
"value": "1"
},
{
"label": "Sessions West Brunswick",
"value": "2"
},
{
"label": "Global",
"value": null
}
]
I need to remove the arrays in the arrayTwo if its value == id in the arrayOne.
Can someone help me…
4
Answers
You can first create a
Set
of all the ids in the first array, then filter the second array based on the existence of the value property in thatSet
.It’s more efficient to create a set of ids first, but you can also do it as a one-liner using
find
like this:You can also do using
find
andfilter
You can use
filter
andsome
like this: