Below is an example of an array object:
const data = [
{
name: "A",
values: [
{
name: "PASS",
value: 36,
},
],
},
{
name: "B",
values: [
{
name: "PASS",
value: 144,
},
],
},
{
name: "C",
values: [
{
name: "PASS",
value: 144,
},
{
name: "FAIL",
value: 256,
},
],
}]
I want to filter out the PASS objects from this data and create a new object with simplified structure as shown below:
[
{
name: "A",
value: 36,
},
{
name: "B",
value: 144,
},
{
name: "C",
value: 144,
}
]
I attempted to achieve this using the code snippet below but encountered issues:
sorted_obj = {}
data.map(item => {
item.values.map(registry => {
if(registry.name === 'PASS'){
sorted_obj.push({item.name:registry.name.value})
}
})
})
Please advise on how I can correct my approach or suggest a better solution. Thank you for your assistance.