递归遍历删除对象中的key

如何通过遍历删除该对象中的createBy、updateBy、createTime、updateTime、scheduleId、delFlag的值 

{
"positionId": "68034",
"operType": "3",
"noticeType": "4",
"sysPublishSchedule": {
"id": "1645598010240192514",
"createBy": "YBJOO20190700002",
"updateBy": "YBJOO20190700002",
"createTime": "2023-04-10 13:55:44",
"updateTime": "2023-04-10 14:03:23",
"delFlag": 0,
"title": "复制-9-4",
"comId": "86010100",
"comName": "北京分公司 密云营业部",
"pushNotictType": "会议",
"startDate": "2023-05-10 00:00:00",
"endDate": "2023-05-22 23:59:59",
"alldayMark": "Y",
"intervalMark": "Y",
"presenter": "发送",
"contact": "许怀玉的反对",
"contactMobile": "13314201245",
"contactPhone": null,
"remark": "的",
"online": "1",
"address": null,
"longitude": null,
"latitude": null,
"seeDeptId": null,
"seeDeptName": null,
"seePosition": "1",
"needNotice": "2",
"noticeType": "",
"share": "1",
"copy": "1",
"state": "1",
"deptId": "3693",
"deptName": "总裁办",
"isEdit": "2",
"deptmanagerCode": "66993",
"seniormanagerCode": "66993",
"submissionTime": "2023-04-10 16:52:04",
"createName": "钟泊",
"bindNotice": [
"4"
],
"bindIsOnline": [
"1"
]
},
"sysScheduleFileList": [
{
"createBy": "YBJOO20190700002",
"updateBy": null,
"createTime": "2023-04-10 13:55:44",
"updateTime": null,
"scheduleId": "1645598010240192514",
"fileType": "1",
"fileName": "6.png",
"fileSize": "21522",
"fileSort": "1",
"filePath": "https://mingya-wps.oss-cn-beijing.aliyuncs.com/adminback/202304/1681106126542_y9LAl1%406.png"
},
{
"createBy": "YBJOO20190700002",
"updateBy": null,
"createTime": "2023-04-10 16:52:04",
"updateTime": null,
"scheduleId": "1645598010240192514",
"fileType": "1",
"fileName": "1 (4).png",
"fileSize": "28902",
"fileSort": "2",
"filePath": "https://mingya-wps.oss-cn-beijing.aliyuncs.com/adminback/202304/1681116630552_FA165n%401%20(4).png"
},
{
"createBy": "YBJOO20190700002",
"updateBy": null,
"createTime": "2023-04-10 16:52:04",
"updateTime": null,
"scheduleId": "1645598010240192514",
"fileType": "2",
"fileName": "导入人员模板.xlsx",
"fileSize": "8807",
"fileSort": "3",
"filePath": "https://mingya-wps.oss-cn-beijing.aliyuncs.com/adminback/202304/1681116637861_n0JjAK%40%E5%AF%BC%E5%85%A5%E4%BA%BA%E5%91%98%E6%A8%A1%E6%9D%BF.xlsx"
},
{
"createBy": "YBJOO20190700002",
"updateBy": null,
"createTime": "2023-04-10 16:52:04",
"updateTime": null,
"scheduleId": "1645598010240192514",
"fileType": "2",
"fileName": "测试.docx",
"fileSize": "9989",
"fileSort": "4",
"filePath": "https://mingya-wps.oss-cn-beijing.aliyuncs.com/adminback/202304/1681116640793_PV9G9M%40%E6%B5%8B%E8%AF%95.docx"
},
{
"createBy": "YBJOO20190700002",
"updateBy": null,
"createTime": "2023-04-10 16:52:04",
"updateTime": null,
"scheduleId": "1645598010240192514",
"fileType": "2",
"fileName": "测试.pptx",
"fileSize": "30000",
"fileSort": "5",
"filePath": "https://mingya-wps.oss-cn-beijing.aliyuncs.com/adminback/202304/1681116647461_d2uBH%40%E6%B5%8B%E8%AF%95.pptx"
},
{
"createBy": "YBJOO20190700002",
"updateBy": null,
"createTime": "2023-04-10 16:52:04",
"updateTime": null,
"scheduleId": "1645598010240192514",
"fileType": "2",
"fileName": "测试ppt.ppt",
"fileSize": "20992",
"fileSort": "6",
"filePath": "https://mingya-wps.oss-cn-beijing.aliyuncs.com/adminback/202304/1681116679801_JxeGqD%40%E6%B5%8B%E8%AF%95ppt.ppt"
}
],
"sysScheduleNoticesList": [],
"sysScheduleOnline": {
"createBy": "YBJOO20190700002",
"updateBy": null,
"createTime": "2023-04-10 13:55:44",
"updateTime": null,
"delFlag": 0,
"scheduleId": "1645598010240192514",
"onlineId": "3",
"onlineName": "其他平台",
"enterpriseId": null,
"platformName": "其他平台",
"meetingLink": null,
"qrcodePath": null
}
}

可以通过遍历对象的属性,判断属性名是否为需要删除的属性名,然后使用 delete 操作符删除该属性。具体实现如下: 

function deleteProperties(obj) {
  for (let prop in obj) {
    if (prop === 'createBy' || prop === 'updateBy' || prop === 'createTime' || prop === 'updateTime' || prop === 'scheduleId' || prop === 'delFlag') {
      delete obj[prop];
    } else if (typeof obj[prop] === 'object') {
      deleteProperties(obj[prop]); // 递归遍历子对象
    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值