Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda