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

191
Views
¿Cómo unir varias matrices en una?

Tengo esta matriz:

 [{"temp":"24.44","time":"2021-11-26 22:23:29.370657"}, {"temp":"25.44","time":"2021-11-26 22:23:35.411530"}]

Y necesito esto:

 data.addRows([ [24.44, [22, 23, 29]], [25.44, [22, 23, 35]] ]);

Es poder hacer un gráfico.

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

0

1) Puede hacer uso del map y split para lograr el resultado deseado.

 const arr = [ { temp: "24.44", time: "2021-11-26 22:23:29.370657" }, { temp: "25.44", time: "2021-11-26 22:23:35.411530" }, ]; const result = arr.map((o) => [ +o.temp, o.time.split(" ")[1].split(".")[0].split(":").map(Number), ]); console.log(result);

2) También puede usar expresiones regulares aquí [^\s]+([^\.]+)/ :

ingrese la descripción de la imagen aquí

 const arr = [ { temp: "24.44", time: "2021-11-26 22:23:29.370657" }, { temp: "25.44", time: "2021-11-26 22:23:35.411530" }, ]; const result = arr.map(({ temp, time }) => { const [a, b, c] = time.match(/[^\s]+([^\.]+)/)[1].split(":"); return [+temp, [+a, +b, +c]]; }); console.log(result);

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!