im trying to get an array based on its element id of array of object and the structure is looks like this
{"data": [
{
"id": 46,
"name": "shsjks",
"desc": "ehejej",
"code": "hshsbsb",
"activation_type": 1,
"detail": "[{\"id\": 413, \"name\": \"A\"}, {\"id\": 416, \"name\": \"B\"}]",
},
{
"id": 47,
"name": "hhksns",
"desc": "benemne",
"code": "gevewk",
"activation_type": 1,
"detail": "[{\"id\": 419, \"name\": \"C\"}, {\"id\": 423, \"name\": \"D\"}]"
},
]}
im trying to get the data based on the detail id and what i did
let arr = a.data.filter(x => {
return (JSON.parse(x.detail).filter(x => x.id === 419))
});
// returned all instead of first element of the array
i want it to returned
// filter where id 419
{
"id": 47,
"name": "shjks",
"detail": "[{\"id\": 419, \"name\": \"C\"}, {\"id\": 423, \"name\": \"D\"}]"
....
}
.length > 0after the second filter, or replace it with.somearr? It will not be an array, right?