Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda