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

221
Visualizações
Filter An Array of Objects based on an array of keywords

I have an array of multiple objects as follows (only showing two for brevity):

const jobs = [
    {
      "id": 1,
      "company": "Photosnap",
      "new": true,
      "featured": true,
      "position": "Senior Frontend Developer",
      "role": "Frontend",
      "level": "Senior",
      "postedAt": "1d ago",
      "contract": "Full Time",
      "location": "USA Only",
      "languages": ["HTML", "CSS", "JavaScript"],
      "tools": ["React", "Sass"]
    },
    {
      "id": 2,
      "company": "Manage",
      "logo": "./images/manage.svg",
      "new": true,
      "featured": true,
      "position": "Fullstack Developer",
      "role": "Fullstack",
      "level": "Midweight",
      "postedAt": "1d ago",
      "contract": "Part Time",
      "location": "Remote",
      "languages": ["Python"],
      "tools": ["React"]
    },

And an array of keywords

const keywords = ['React', 'Fullstack', 'Vue']

I would like to filter my jobs array to return any job which contains ANY of the keywords in my keywords array.The keyword array is dynamic and may only include one term or several. I think the array.prototype.filter is my starting point but I cannot figure out how to return objects which include any of my keywords.

  let result = jobs.filter(function(obj) {
      ...
  })`
 
Could someone help?
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use filter, some and includes

let jobs = [{"id": 1,"company": "Photosnap","new": true,"featured": true,"position": "Senior Frontend Developer","role": "Frontend","level": "Senior","postedAt": "1d ago","contract": "Full Time","location": "USA Only","languages": ["HTML", "CSS", "JavaScript"],"tools": ["React", "Sass"]},{"id": 2,"company": "Manage","logo": "./images/manage.svg","new": true,"featured": true,"position": "Fullstack Developer","role": "Fullstack","level": "Midweight","postedAt": "1d ago","contract": "Part Time","location": "Remote","languages": ["Python"],"tools": ["React"]}, {"id": 3,"company": "Manage","logo": "./images/manage.svg","new": true,"featured": true,"position": "Fullstack Developer","role": "Fullstack","level": "Midweight","postedAt": "1d ago","contract": "Part Time","location": "Remote","languages": ["Python"],"tools": ["Angular"]}]
const keywords = ['React', 'Fullstack', 'Vue']

let results = jobs.filter(job => {
  return job.tools.some(v => keywords.includes(v))
})

console.log(results)

You can improve time complexity by using Set

let jobs = [{"id": 1,"company": "Photosnap","new": true,"featured": true,"position": "Senior Frontend Developer","role": "Frontend","level": "Senior","postedAt": "1d ago","contract": "Full Time","location": "USA Only","languages": ["HTML", "CSS", "JavaScript"],"tools": ["React", "Sass"]},{"id": 2,"company": "Manage","logo": "./images/manage.svg","new": true,"featured": true,"position": "Fullstack Developer","role": "Fullstack","level": "Midweight","postedAt": "1d ago","contract": "Part Time","location": "Remote","languages": ["Python"],"tools": ["React"]}, {"id": 3,"company": "Manage","logo": "./images/manage.svg","new": true,"featured": true,"position": "Fullstack Developer","role": "Fullstack","level": "Midweight","postedAt": "1d ago","contract": "Part Time","location": "Remote","languages": ["Python"],"tools": ["Angular"]}]
const keywords = new Set(['React', 'Fullstack', 'Vue'])

let results = jobs.filter(job => {
  return job.tools.some(v => keywords.has(v))
})

console.log(results)

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