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

148
Views
¿Cómo se devuelven los valores de los objetos solo de cada objeto de una matriz de objetos?

Así que estoy ejecutando una instancia sin servidor de NodeJS, usando Knex.js como mi middleware de base de datos. Cuando intento devolver SOLO el valor de una solicitud a Knex, siempre obtengo [ { vrn: 'xx12xyz' } ] . He intentado usar Object(), ¿alguien tiene una función de ayuda rápida o pequeña que pueda ayudarme a aplanar esto en una matriz directa de modo que pueda seleccionar SOLO el valor?

Este es el código que estoy usando:

 const vrnList = await db('vehicles').select('vrn').where('id', '=', '1'); console.log("The quick car with the VRN ", Object.values(vrnList), " overtook me on the freeway");

TL; DR: dividir el objeto y la identificación de la matriz de los valores

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

0

Prueba este:

 let onlyValues = vrnList.map(result => result.vrn);
about 4 years ago · Juan Pablo Isaza Report

0

Dado que el OP parece recuperar la clave de valor (s) agnóstica a través Object.values que devuelve una matriz de valores, el OP también necesita utilizar flatMap ...

 vrnList.flatMap(item => Object.values(item)) 

 console.log( [ { vrn: 'xx12xyz' } ].flatMap(item => Object.values(item)) ); console.log( [ { vrn: 'xx12xyz' }, { vrn: 'xx98abc' }, { vrn: 'yy34xyz' }, ].flatMap(item => Object.values(item)) );
 .as-console-wrapper { min-height: 100%!important; top: 0; }

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!