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

86
Vistas
How to compare an object with an array and return a value

Say I have an object structured like this:

const carObj = {"1234":"Corvette","4321":"Subaru","8891":"Volvo"};

And I have an array that represents the key (or ID):

const myArray = [1234, 4321, 8891, 1234, 4321]

I want a loop, function, or something that will go through the object of arrays and return the value for the corresponding key. I am using vue.js and attempting to do this in a computed method. Any help would be much appreciated.

Expected output:

Corvette
Subaru
Volvo
Corvette
Subaru
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Just map the numbers array the returns new one based on the keys of the object :

 const result = myArray.map(item=>carObj[item])

computed property :

computed:{
   result(){
        return this.myArray.map(item=>this.carObj[item])
      }

}
about 4 years ago · Juan Pablo Isaza Denunciar

0

const carObj = {"1234":"Corvette","4321":"Subaru","8891":"Volvo"};
const myArray = [1234, 4321, 8891, 1234, 4321];

myArray.forEach((item) => {
  console.log(carObj[item]);
});

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