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

174
Visualizações
return the value of the matching items in an array

I have two arrays that I would like to compare and return a respective value of the ones that match.

Taking the 'id' variable as a reference, I want to return all the matching values of fastFood, but only the 'name'.

My expected result is to return Five Guys and KFC, but instead, it returns the entire object.

let id = ['1234'];
let fastFood = [
  {_id:'4391', name: "McDonalds"}, 
  {_id:'7654', name: "Burger King"}, 
  {_id:'8765', name: "Dominos"}, 
  {_id:'1234', name: "Five Guys"}, 
  {_id:'9876', name: "Subway"}, 
  {_id:'1234', name: "KFC"}
];


const findFastFood = ids.filter((item) => {
  if (item._id.indexOf(id) !== -1) {
    return item.name;
  }
});

console.log(findFastFood);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Does this help?

let id = ['1234'];
let fastFood = [{
    _id: '4391',
    name: "McDonalds"
  },
  {
    _id: '7654',
    name: "Burger King"
  },
  {
    _id: '8765',
    name: "Dominos"
  },
  {
    _id: '1234',
    name: "Five Guys"
  },
  {
    _id: '9876',
    name: "Subway"
  },
  {
    _id: '1234',
    name: "KFC"
  }
];


const findFastFood = fastFood.filter((item) => {
  if (id.indexOf(item._id) !== -1) {
    return item.name
  }

}).map(obj => obj.name);


console.log(findFastFood);

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