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

139
Views
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 answers
Answer question

0

Try this one:

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

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 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!