Javascript JS希望迭代并将嵌套对象中每个键的值设置为空&引用;,并创建此类对象的数组

Javascript JS希望迭代并将嵌套对象中每个键的值设置为空&引用;,并创建此类对象的数组,javascript,node.js,nested,iteration,javascript-objects,Javascript,Node.js,Nested,Iteration,Javascript Objects,基本对象: obj = { "place": "{{base_gplaceId}}", "feedInputs": [ { "subCategoryQuestion": "{{base_gquestionId}}", "context": "other", "image": "abc.jpg", "mediaMetadata": { "s

基本对象:

obj = {
    "place": "{{base_gplaceId}}",
    "feedInputs": [
        {
            "subCategoryQuestion": "{{base_gquestionId}}",
            "context": "other",
            "image": "abc.jpg",
            "mediaMetadata": {
                "stickerList": [
                    {
                        "id": "someid2",
                        "sticker": "delish",
                        "weight": 3
                    }
                ],
                "textList": [
                    {
                        "text": "What an evening!!!"
                    }
                ]
            }
        }
    ]
};
更多的键可以有更多的嵌套

要逐个设置keys=”“的值,并将更新的对象推送到数组中吗

预期OP:

[
{"place":"","feedInputs":[{"subCategoryQuestion":"{{base_gquestionId}}","context":"other","image":"abc.jpg","mediaMetadata":{"stickerList":[{"id":"someid2","sticker":"delish","weight":3}],"textList":[{"text":"Whatanevening!!!"}]}}]},

{"place":"{{base_gplaceId}}","feedInputs":[{"subCategoryQuestion":"","context":"other","image":"abc.jpg","mediaMetadata":{"stickerList":[{"id":"someid2","sticker":"delish","weight":3}],"textList":[{"text":"Whatanevening!!!"}]}}]},

{"place":"{{base_gplaceId}}","feedInputs":[{"subCategoryQuestion":"{{base_gquestionId}}","context":"","image":"abc.jpg","mediaMetadata":{"stickerList":[{"id":"someid2","sticker":"delish","weight":3}],"textList":[{"text":"Whatanevening!!!"}]}}]},

{"place":"{{base_gplaceId}}","feedInputs":[{"subCategoryQuestion":"{{base_gquestionId}}","context":"other","image":"","mediaMetadata":{"stickerList":[{"id":"someid2","sticker":"delish","weight":3}],"textList":[{"text":"Whatanevening!!!"}]}}]},

{"place":"{{base_gplaceId}}","feedInputs":[{"subCategoryQuestion":"{{base_gquestionId}}","context":"other","image":"abc.jpg","mediaMetadata":{"stickerList":[{"id":"","sticker":"delish","weight":3}],"textList":[{"text":"Whatanevening!!!"}]}}]}
,...........]

尝试了几次递归,但在嵌套对象内部更新后无法中断,
任何简单的方法?

您可以迭代属性并更改非对象的值。为了访问完整的对象,还需要存储根,并使用stringify和parse为结果集获取对象的副本

函数visitAll(对象,根=对象){
返回对象
.keys(对象)
.flatMap(k=>{
if(object[k]&&typeof object[k]=“object”)返回visitAll(object[k],root);
常量值=对象[k];
对象[k]='';
const result=JSON.parse(JSON.stringify(root));
对象[k]=值;
返回结果;
});
}
var object={place:{{base\u gplaceId}}],feedInputs:[{subcategory问题:{{{base\u gquestionId}}],上下文:“其他”,图像:“abc.jpg”,媒体元数据:{stickerList:[{id:'someid2],贴纸:“delish”,权重:3}],文本列表:[{text:“多么美好的夜晚!!!”}},
结果=可视高度(对象);
forEach(o=>console.log(JSON.stringify(o))

。作为控制台包装{max height:100%!important;top:0;}
您可以迭代属性并更改非对象的值。为了访问完整的对象,还需要存储根,并使用stringify和parse为结果集获取对象的副本

函数visitAll(对象,根=对象){
返回对象
.keys(对象)
.flatMap(k=>{
if(object[k]&&typeof object[k]=“object”)返回visitAll(object[k],root);
常量值=对象[k];
对象[k]='';
const result=JSON.parse(JSON.stringify(root));
对象[k]=值;
返回结果;
});
}
var object={place:{{base\u gplaceId}}],feedInputs:[{subcategory问题:{{{base\u gquestionId}}],上下文:“其他”,图像:“abc.jpg”,媒体元数据:{stickerList:[{id:'someid2],贴纸:“delish”,权重:3}],文本列表:[{text:“多么美好的夜晚!!!”}},
结果=可视高度(对象);
forEach(o=>console.log(JSON.stringify(o))

。作为控制台包装器{max height:100%!important;top:0;}
您能否尝试澄清您到底想做什么?也许可以在例子中添加一些例子或细节。你能试着澄清一下你到底想做什么吗?可能会在示例中添加一些示例或详细信息。感谢设置为空和空的工作。当我尝试
删除对象[k]
时,在
对象[k]=''
要从对象中删除属性,最终的输出会完全变形,我最终删除了所有属性,而不是每个输出对象中的一个属性。感谢您将其设置为空&Null。当我尝试
删除对象[k]
时,在
对象[k]=''
要从对象中删除属性,最终输出会完全变形,我最终会删除所有属性,而不是每个输出对象中的一个。