• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

66
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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error