Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
nested filter array javascript

I want to create a nested filter in js when I filter my array primary data is affected and changed but I need preliminary data to remove filters

my js code :

    let result = companies;
     result.map((item, i) => {212
           let rows = [...result[i].table.table_rows].filter((item3) => {
              return Object.keys(item3).some(i => item3[i][key] === value[key]);
           });
                      
           result[i].table.table_rows = [...rows];
           return result[i];
        });
      arrayFilter(result);

my data is:

{
  "companies": [
    {
      "company": {
        "name": "company 1"
      },
      "table": {
        "table_rows": [
          {
            "cells": {
              "product_name": "prod1",
              "pa_size": "12"
            }
          },
          {
            "cells": {
              "product_name": "prod2",
              "pa_size": "15"
            }
          }
        ]
      }
    },
    {
      "company": {
        "name": "company 2"
      },
      "table": {
        "table_rows": [
          {
            "cells": {
              "product_name": "prod2-1",
              "pa_size": "12"
            }
          },
          {
            "cells": {
              "product_name": "prod2-2",
              "pa_size": "18"
            }
          }
        ]
      }
    }
  ]
}

I tried many ways to solve this problem, but I did not get the right answer

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Your question is not clear, the point I have understand that you wanted to filter the array "table_rows" located inside each companies array object? map and filter returns new array, so the solution for this is:

result = result.companies.map((item, i) => {
   const newItem = {...item};
   let rows = newItem .table.table_rows.filter((item3) => {
      return Object.keys(item3).some(i => item3[i][key] === value[key]);
   });
              
   newItem.table_rows = [...rows];
   return newItem ;
});
arrayFilter(result);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!