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

202
Views
How to join several arrays in one?

I have this array:

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

And I need this:

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

It is to be able to make a graph.

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

0

1) You can make use of map and split to achieve the desired result.

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) You can also use regex here [^\s]+([^\.]+)/:

enter image description here

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!