gpt4 book ai didi

javascript - 如何解析存储在数组中的数据

转载 作者:行者123 更新时间:2023-11-30 14:12:08 25 4
gpt4 key购买 nike

我有一个正在使用的 CSV 文件。我不想将它转换为具有键和值的对象。我希望能够创建更多数组来存储不同的值即温度哼小时雪深等所有这些都是具有 7 个值的数组

现在,这就是 csv 存储在数据数组中的方式

  1. "11/28/2018 7:30,1128,-2.122,86.2,34.06,1.178,320.2,20.4" ​
  2. "11/28/2018 7:45,1129,-2.325,85.6,34.54,1.771,325.5,30.72" ​
  3. "11/28/2018 8:00,1130,-2.679,85.7,30.73,1.764,312.1,28.98" ​
  4. "11/28/2018 8:15,1131,-2.872,88,34.55,1.073,306.6,25.65" ​
  5. "11/28/2018 8:30,1132,-2.953,90.7,35.25,1.247,311.2,30.06" ​
  6. "11/28/2018 8:45,1133,-3.064,93.3,35,1.449,312.6,30.13" ​
  7. "11/28/2018 9:00,1134,-2.771,91.5,33.44,0.988,311,28.27" ​ length: 7

第一列是时间戳,第二列是记录号,第三列是温度,第四列是湿度等等。

function get_Data(data) {
"use strict";
var fileData = new Array();
data = data.split(/\r\n|\r|\n/);
data = data.slice(Math.max(data.length - 7, 0));
createGraph(data);
}

我想要这样的数组

Tem = [-2.122, -2.325, -2.679, -2.872 ...]

小时数 = [7:30、7:45、8:00、8:15 ...]

最佳答案

简单 - mapsplit 为每个逗号,然后查看它应该是哪个项目的索引:

var data = ["11/28/2018 7:30,1128,-2.122,86.2,34.06,1.178,320.2,20.4",
"11/28/2018 7:45,1129,-2.325,85.6,34.54,1.771,325.5,30.72",
"11/28/2018 8:00,1130,-2.679,85.7,30.73,1.764,312.1,28.98",
"11/28/2018 8:15,1131,-2.872,88,34.55,1.073,306.6,25.65",
"11/28/2018 8:30,1132,-2.953,90.7,35.25,1.247,311.2,30.06",
"11/28/2018 8:45,1133,-3.064,93.3,35,1.449,312.6,30.13",
"11/28/2018 9:00,1134,-2.771,91.5,33.44,0.988,311,28.27",
];

var items = {
date: [],
recordNumber: [],
temperature: [],
humidity: [],
value5: [],
value6: [],
value7: [],
value8: [],
};

Object.keys(items).forEach((key, index) => items[key].push(data.map(str => str.split(",")[index])));

console.log(items);

关于javascript - 如何解析存储在数组中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54226952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com