【问题标题】:How to deselect a nested JSON object?如何取消选择嵌套的 JSON 对象?
【发布时间】:2019-08-16 15:21:04
【问题描述】:

目前我的代码是console.log("body:", body.readResults)。但我不想要 tr 的值。如何取消选择它们并获得其余部分?

"readResults": [
   {
       "id": "Channel1.Device1.Coil",
       "s": true,
       "r": "",
       "v": true,
       "t": 1553586722927
    }
]

【问题讨论】:

标签: javascript node.js json


【解决方案1】:

你可以轻松做到:

function cleanMyResult(result) {
    const cleanResult = Object.assign({}, result); // this will preserve your original object, but it costs some performance
    delete cleanResult.t;
    delete cleanResult.r;
    return cleanResult;
}

const cleanedResults = body.readResults.map(cleanMyResult);
console.log(cleanedResults);

请同时查看 SO 上很多已经很好的答案:

【讨论】:

  • @YaHtet 好!因此,请使用复选标记接受我的回答,以便其他人能够快速了解​​您的问题已解决。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-28
  • 2023-01-18
相关资源
最近更新 更多