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

140
Vistas
How does one return the object values only from each object of an array of objects?

So I am running a NodeJS Serverless instance, using Knex.js as my DB middleware. When attempting to return JUST the value from a request to Knex, I always get [ { vrn: 'xx12xyz' } ]. I have tried using Object(), does anyone have a quick one liner or small helper function that can help me flatten this into a direct array such that I can pick out JUST the value?

This is the code I am using:

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: Splitting the object and array id from the values

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

0

Try this one:

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

0

Since the OP seems to retrieve the value(s) key agnostic via Object.values which returns an array of values, the OP in addition needs to utilize 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 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