js [ { "18900": [ { "memory": 4.06, "hardDisk": 12.9, "cpu": 16.67, "time": "2023-05-24 10:10:00" }, { "memory": 1.14, "hardDisk": 12.9, "cpu": 13.95, "time": "2023-05-21 18:10:00" }, { "memory": 3.87, "hardDisk": 12.9, "cpu": 11.9, "time": "2023-05-21 17:00:00" }, { "memory": 9.92, "hardDisk": 17.7, "cpu": 17.68, "time": "2023-05-19 17:00:00" } ], "19000": [ { "memory": 2.2, "hardDisk": 17.7, "cpu": 25, "time": "2023-05-24 10:10:00" }, { "memory": 1.53, "hardDisk": 15.8, "cpu": 4.76, "time": "2023-05-21 16:40:00" }, { "memory": 1.91, "hardDisk": 15.8, "cpu": 4.88, "time": "2023-05-21 16:30:00" }, { "memory": 1.79, "hardDisk": 15.8, "cpu": 8.54, "time": "2023-05-21 16:00:00" } ] } ]在不知道有多少端口情况下 这是怎么使用for循环
时间: 2023-12-10 15:06:18 浏览: 137
可以使用 for...in 循环来遍历对象中的属性,代码如下:
```
const data = [ /* 数据 */ ];
for (let i = 0; i < data.length; i++) {
const portData = data[i];
for (const port in portData) {
const records = portData[port];
console.log(`Port ${port}:`);
for (let j = 0; j < records.length; j++) {
const record = records[j];
console.log(` ${record.time}: CPU ${record.cpu}%, Memory ${record.memory}%, Hard Disk ${record.hardDisk}%`);
}
}
}
```
这样可以输出每个端口的记录信息。
阅读全文