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

92
Views
Get an array containing values of dynamic object property from the given array

I have an array like this-

[{a:23},{b:23},{r:2323},{e:99}]

I want to convert this to a new array containing only the object property values like-

[23,23,2323,99]

I have tried all the methods but could not figure out the way. Can anyone suggest me the idea for this please.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Just use .flatMap and Object.values

const data = [{a:23}, {b:23}, {r:2323}, {e:99}];

const result = data.flatMap(Object.values);

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0 }

about 4 years ago · Santiago Trujillo Report

0

let array = [ { a: 23 }, { b: 23 }, { r: 2323 }, { e: 99 } ]
let array1 = []

for (const obj of array) {
  array1.push(obj[Object.keys(obj)[0]])
}

console.log(array1) // [23, 23, 2323, 99]
  • obj[Object.keys(obj)[0]] returns the first property of the object obj (source)
about 4 years ago · Santiago Trujillo 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!