My object array (in Json format) looks like this:
var datas = [
{
"Id": "1",
// Includes 10 fields
"tests": [
{
"id":"1-1",
"isSelected": true,
},
{
"id":"1-2",
"isSelected": false,
},
]
},
{
"Id": "2",
// Includes 10 fields
"tests": [
{
"id":"2-1",
"isSelected": true,
},
{
"id":"2-2",
"isSelected": true,
},
]
},
{
"Id": "3",
// Includes 10 fields
"tests": [
{
"id":"3-1",
"isSelected": false,
},
{
"id":"3-2",
"isSelected": false,
},
]
}
]
After trying the code below:
var filteredData = datas.filter( t => t.tests.filter(o => o.isSelected));
I need the data in the following format:
[
{
"Id": "1",
// Includes 10 fields
"t": [
{
"id":"1-1",
"isSelected": true,
}
]
},
{
"Id": "2",
// Includes 10 fields
"tests": [
{
"id":"2-1",
"isSelected": true,
},
{
"id":"2-2",
"isSelected": true,
},
]
}
]