gpt4 book ai didi

javascript - Mikrotik JS JSON 到数组对象

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

[
{
"field": ".id",
"value": "*0"
},
{
"field": "name",
"value": "default-trial"
},
{
"field": "uptime",
"value": "0s"
},
{
"field": "comment",
"value": "counters and limits for trial users"
}
],

将其转换为对象的最快方法是哪一种?我想要一个这样的对象

用户{ 编号:0, 名称:默认试用, ...

最佳答案

是这样的吗?

'use strict';

const arr = [
{
"field": ".id",
"value": "*0"
},
{
"field": "name",
"value": "default-trial"
},
{
"field": "uptime",
"value": "0s"
},
{
"field": "comment",
"value": "counters and limits for trial users"
}
];

const obj = arr.reduce((acc, { field, value }) => {
acc[field] = value;
return acc;
}, {});

console.log(obj);

关于javascript - Mikrotik JS JSON 到数组对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54725102/

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