I have two arrays of objects, and what I need to do is create a new array based on arrayOfItems
where it doesn’t include the same value found in itemX[0].nestedArrayOfItems
However, whats throwing me for a loop here is I don’t know how to handling filtering when the keys in itemX[0].nestedArrayOfItems
could be anything.
Usually it be a common key like id
and you could just go
const results = arrayOfItems.filter(item => !itemX[0].nestedArrayOfItems.some(({ id }) => id === item.id))
but sadly it’s not the case and gap in my knowledge means I can’t figure it out.
const arrayOfItems = [
{
id: '4321-3321-4423',
value: 'some text'
},
{
id: '4322-4654-9875',
value: 'some text again'
}
]
const itemX = [
{
id: '3214-6543-4321',
nestedArrayOfItems: [
{"1" : '4321-3321-4423'},
{"2" : '3455-8765-7764'}
]
}
]