Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
Cómo comparar un objeto con una matriz y devolver un valor

Digamos que tengo un objeto estructurado así:

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

Y tengo una matriz que representa la clave (o ID):

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

Quiero un bucle, una función o algo que pase por el objeto de las matrices y devuelva el valor de la clave correspondiente. Estoy usando vue.js e intento hacer esto en un método computarizado. Cualquier ayuda sería muy apreciada.

Rendimiento esperado:

 Corvette Subaru Volvo Corvette Subaru
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Simplemente asigne la matriz de números que devuelve una nueva basada en las claves del objeto:

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

propiedad calculada:

 computed:{ result(){ return this.myArray.map(item=>this.carObj[item]) } }
about 4 years ago · Juan Pablo Isaza Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!