I have this JSON that I'm filtering


this.filteredMisc = this.missions.filter( mission => misc?.Name?.toLowerCase().includes(evt.target.value.toLowerCase()) 
                                                            || misc?.Status__c?.toLowerCase().includes(evt.target.value.toLowerCase())
                                                            || misc?.Tasks__r?.Assigned_Agency__r?.Name?.toLowerCase().includes(evt.target.value.toLowerCase())

JSON misc

    "Id": "a2b3S000000ddddddO",
    "Name": "20-xxxx-00021",
    "Status__c": "En Route",
    "Tasks__r": [{
        "Sub_Summary__c": "a2b3S000000ss1sssO",
        "Name": "T-000130",
        "Summary__c": "cxb",
        "Status__c": "Check",
        "Agency__r": {
            "Name": "gwsdfg",
            "Id": "0013S00000GOhjiQAL"
    }, {
        "Sub_Summary__c": "a2b3S000000ss2sssO",
        "Name": "T-000129",
        "Summary__c": "test",
        "Status__c": "On",
        "Agency__r": {
            "Name": "County",
            "Id": "0013S00000CfgfHQAV"
. . .

Name and State work just fine, however when I need to drill down into an object like Tasks__r it fails because I need to iterate through them. Is there an easy way to do this?

1 Answer 1


This is more of a specific JS question.Since we just need to check if any one array element satisfies the condition, we can use JS some function for checking the nested array as below :

const eventValue = evt.target.value.toLowerCase();
this.filteredMisc = this.missions.filter(mission => {
    return mission.Name.toLowerCase().includes(eventValue) || mission.Status__c?.toLowerCase().includes(eventValue) ||
        mission.Tasks__r.some(task => task.Assigned_Agency__r?.Name?.toLowerCase().includes(eventValue))

Also , evt.target.value.toLowerCase() can be stored in a variable once and used wherever needed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .