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

280
Views
JavaScript: Extract values of a specific key out of key-value array and store them in a new array

I have an' multidimensional key-value array like this:

'[[
{"_time":"2022-01-03T00:00:00Z","_value":10.70140000000014,"ts":1641168000000},
{"_time":"2022-01-04T00:00:00Z","_value":13.002499999999767,"ts":1641254400000},
{"_time":"2022-01-05T00:00:00Z","_value":16.171700000000182,"ts":1641340800000},
{"_time":"2022-01-06T00:00:00Z","_value":17.48929999999981,"ts":1641427200000},
]]'

and I need the values from each of them in a new variable in this way:

[10.70140000000014,13.002499999999767,16.171700000000182,17.48929999999981]

I tried it with map but that do not match my needs:

function getPreparedData(data) {
  if (data) {
  return data[0].map(elm => ({
      a: elm._value
  }));
  }
   return [];
};

How can I solve this?

Thanks

Frank

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

0

In your example, the function getPreparedData is returning array of objects. You actually want to return an array of values (where values are just the value of the _value property)

const data = [[
{"_time":"2022-01-03T00:00:00Z","_value":10.70140000000014,"ts":1641168000000},
{"_time":"2022-01-04T00:00:00Z","_value":13.002499999999767,"ts":1641254400000},
{"_time":"2022-01-05T00:00:00Z","_value":16.171700000000182,"ts":1641340800000},
{"_time":"2022-01-06T00:00:00Z","_value":17.48929999999981,"ts":1641427200000},
]];

function getPreparedData(data) {
  return data[0].map(elm => elm._value)
};

const res = getPreparedData(data);
console.log(res);

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!