[ { "id": 12, "created_at": "2023-05-31T04:12:56.000Z", "updated_at": "2023-06-11T23:48:02.000Z", "gatewayMac": "e491127eaa15", "deviceId": "710no22", "pointId": "710no22", "pointName": "710二氧化氮2", "value": "1" } ]JavaScript中只留下value
时间: 2023-07-08 11:56:17 浏览: 139
你可以使用map()方法和解构赋值来实现这个问题的需求,例如:
```
const arr = [
{
"id": 12,
"created_at": "2023-05-31T04:12:56.000Z",
"updated_at": "2023-06-11T23:48:02.000Z",
"gatewayMac": "e491127eaa15",
"deviceId": "710no22",
"pointId": "710no22",
"pointName": "710二氧化氮2",
"value": "1"
}
];
const values = arr.map(({ value }) => value);
console.log(values); // ["1"]
```
这里我们使用了解构赋值来获取每个对象中的value属性,并且使用map()方法将所有的value属性值提取出来组成一个新的数组。
相关问题
}, { "id": 8, "created_at": "2023-05-31T04:01:11.000Z", "updated_at": "2023-05-31T04:01:11.000Z", "gatewayMac": "e491127eaa15", "deviceId": "710co", "pointId": "710co1", "pointName": "710一氧化碳1", "value": "0" }, { "id": 9, "created_at": "2023-05-31T04:10:34.000Z", "updated_at": "2023-05-31T04:10:34.000Z", "gatewayMac": "e491127eaa15", "deviceId": "710no2", "pointId": "710no2", "pointName": "710二氧化氮", "value": "4" }, { "id": 10, "created_at": "2023-05-31T04:11:36.000Z", "updated_at": "2023-05-31T04:11:36.000Z", "gatewayMac": "e491127eaa15", "deviceId": "710co2", "pointId": "710co2", "pointName": "710一样化碳2", "value": "0" }, { "id": 11, "created_at": "2023-05-31T04:12:08.000Z", "updated_at": "2023-05-31T05:19:39.000Z", "gatewayMac": "e491127eaa15", "deviceId": "710o22", "pointId": "710o22", "pointName": "710氧气2", "value": "205" }, {
I'm sorry, but your question is incomplete. It looks like you copied and pasted some code related to device readings from a database. Can you please provide a complete question or clarify what you would like me to help you with?
阅读全文