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

277
Views
JavaScript: extraiga los valores de una clave específica de la matriz clave-valor y guárdelos en una nueva matriz

Tengo una matriz multidimensional de clave-valor como esta:

 '[[ {"_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}, ]]'

y necesito los valores de cada uno de ellos en una nueva variable de esta manera:

 [10.70140000000014,13.002499999999767,16.171700000000182,17.48929999999981]

Lo probé con map pero eso no coincide con mis necesidades:

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

¿Como puedo resolver esto?

Gracias

Franco

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

0

En su ejemplo, la función getPreparedData devuelve una matriz de objetos. En realidad, desea devolver una matriz de valores (donde los valores son solo el valor de la propiedad _value )

 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!