如何通过值中存在字符串来递归过滤对象?

I have an object with different values. An object may have a large nesting depth. I need to filter the mainObj by the presence of a string "saved" in values.

   mainObj = {
    id: "37864bcdjdd", 
    values1: {
       value: [
          {item1: "saved item1", item2: "saved item2"},
          {id: "3434", someItem: "another item"}
       ]
    }
    values2: [
       {item3: "item3", item4: "saved item4"},
       {id: "saved id", item5: "item5 value"}
    ] 

结果,我想得到一个对象,其中包含一个给定值的元素。像这样

   resultObj = {
    id: "37864bcdjdd", 
    values1: {
       value: [
          {item1: "saved item1", item2: "saved item2"},
          {id: "3434", someItem: ""}
       ]
    }
    values2: [
       {item3: "", item4: "saved item4"},
       {id: "saved id", item5: ""}
    ] 

但我绝对不能考虑id。

评论