I am currently facing an issue with filtering an array of nested objects. The problem arises when trying to filter the parent object based on a specific property within its child object.
let line = "xyz";
let data = [
{
"header": {
"po_no": "P.O. Number"
},
"line": line
},
{
"header": {
"po_no": "Another P.O. Number"
},
"line": line
}
];
...
data.filter(item => {
return item.header.po_no === 'P.O. Number' // This condition should evaluate to true
})
The desired outcome is to retrieve the entire item
object when the value of header.po_no
matches a certain string.
However, I am encountering difficulties as no values are being returned even when the evaluation conditions are met.
Expected output:
[{
"header": {
"po_no": "P.O. Number"
},
"line": line
}]
Any suggestions on how I can successfully retrieve the index of the array that meets the criteria of matching a sub-property using a filter?