如何将多个数组合并为一个?

How to join several arrays in one?

我有这个数组:

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

我需要这个:

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

就是会做图

1)你可以利用map and split达到你想要的效果。

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) 你也可以在这里使用正则表达式 [^\s]+([^\.]+)/:

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);