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

97
Views
Typescript data filtering on nested array based on another array

Im new to TS I have an array of data that looks like this

const AllJobs = [
      {
        title: Teller,
        salary: ["Hourly"],
        industries: [
          "Accounting",
          "Banking",
          "Data"
        ]
      },
      {
        title: Scientist,
        salary: ["Yearly"],
        industries: [
          "Biology",
          "Chemicals",
          "Science"
        ]
      },
        {
        title: Artist,
        salary: ["Hourly"],
        industries: [
          "Design",
          "Paint",
          "Color"
        ]
      },
    ];

let desiredSkills = ["Design","Accounting","Data"];

I want to loop over a the data in the "industries" in the AllJobs array and check if any of those vales match any of the values in desiredSkills. If no matching values, filter out that object. I don't know if im doing this right at all.

Desired results:

 const AllJobs = [
          {
            title: Teller,
            salary: ["Hourly"],
            industries: [
              "Accounting",
              "Banking",
              "Data"
            ]
          },
            {
            title: Artist,
            salary: ["Hourly"],
            industries: [
              "Design",
              "Paint",
              "Color"
            ]
          },
        ];

Here is my previous code. That is currently not working.

const getSuggested = (item: string) => {
   const filterIndustry = this.allJobs.filter((x:any) => x['industries'].every((y: string | any[])=> y.includes(item)));
  };
this.desiredIndustries.forEach(getSuggested);

I have also tried

 const getSuggested = (item: string) => {
 let k = item;

 const data = this.allJobs.filter((item: { industries: any }) => item.industries == k);
 console.log(data);
 };
 this.desiredIndustries.forEach(getSuggested);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't really need TypeScript here, so here's a JS solution for you:

const AllJobs = [{
    title: 'Teller',
    salary: ['Hourly'],
    industries: ['Accounting', 'Banking', 'Data'],
  },
  {
    title: 'Scientist',
    salary: ['Yearly'],
    industries: ['Biology', 'Chemicals', 'Science'],
  },
  {
    title: 'Artist',
    salary: ['Hourly'],
    industries: ['Design', 'Paint', 'Color'],
  },
];

let desiredSkills = ['Design', 'Accounting', 'Data'];

const result = AllJobs.filter(({
  industries
}) => industries.find((industry) => desiredSkills.includes(industry)));

console.log(result);

Should be easy to translate to TS. Hope it helps!

about 4 years ago · Juan Pablo Isaza 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!