Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 Respostas
Responde à pergunta

0

Try this one:

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

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda