Good evening
Wondering if anyone could give me hand, I seem to be going in circles
I am trying to get all the objects containing the key/field "type" from an array, by another array of strings.
{
"someData": [
{
"date": "someDate",
"someNestedData": [
{
"id": "1",
"type": "type1",
"dateCreated": "someDate"
},
{
"id": "2",
"type": "type2",
"dateCreated": "someDate"
}
]
},
{
"date": "someDate",
"someNestedData": [
{
"id": "3",
"type": "type1",
"dateCreated": "someDate"
},
{
"id": "4",
"type": "type4",
"dateCreated": "someDate"
}
]
}
]
}
and another array of strings const types = ['type1', 'type2]`
I am trying to filter out the array so that any object not containing the key in the types array is filtered out.
So the end result would be
{
"someData": [
{
"date": "someDate",
"someNestedData": [
{
"id": "1",
"type": "type1",
"dateCreated": "someDate"
},
{
"id": "2",
"type": "type2",
"dateCreated": "someDate"
}
]
},
{
"date": "someDate",
"someNestedData": [
{
"id": "3",
"type": "type1",
"dateCreated": "someDate"
},
]
}
]
}
I have tried something along the lines of
data.someData.someNestedData.indexOf(function (i) {
return types.indexOf(i.type);
})
as well as a few other bloated approaches, just not coming right and looking for something quite performant. TIA :)