gpt4 book ai didi

javascript - 将对象数组添加到现有对象

转载 作者:行者123 更新时间:2023-12-01 00:30:58 24 4
gpt4 key购买 nike

我有一个现有的 params 对象,如下所示

{
"application_context": {
"application_id": "a0",
"context_id": "c0"
},
"device_data": {
"device_id": "",
"hostname": ""
},
"query_options": {
"page_token": "",
"page_size": 30
}
}

我想要的对象应该如下

{
"application_context": {
"application_id": "a0",
"context_id": "c0"
},
"device_data": {
"device_id": "",
"hostname": ""
},
"query_options": {
"page_token": "",
"page_size": 30,
"filter_list": [{
"operator": "OPERATOR_AND",
"field_list": [{
"field": "State",
"value": "INACTIVE_STATE"
}]
}]
}
}

我创建了以下内容

param['filter_list'] = [{
'operator': 'OPERATOR_AND',
'field_list': filter
}];

其中添加以下部分和一些逻辑

"field": "State",
"value": "INACTIVE_STATE"

但无法添加上述内容来获取完整的对象

最佳答案

您需要在query_options键上创建filter_list

let data = {
"application_context": {
"application_id": "a0",
"context_id": "c0"
},
"device_data": {
"device_id": "",
"hostname": ""
},
"query_options": {
"page_token": "",
"page_size": 30
}
}

data.query_options.filter_list = [{
"operator": "OPERATOR_AND",
"field_list": [{
"field": "State",
"value": "INACTIVE_STATE"
}]
}];


console.log(data)

关于javascript - 将对象数组添加到现有对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58535037/

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