Javascript检索多层级对象是否包含有某字符串的key

检索多层级对象是否包含有某字符串的key(value为同类思路) 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="hello">
 </head>

 <body>
 
 </body>
 <script>
var cd={
  "op" : "update",
  "ns" : "db.nihaoTjbwVO",
  "command" : {
    "q" : {
      "$or" : [{
          "_RW_.rwbm.rwztbm" : "58",
          "_RW_.rwbm.yssj" : {
            "$lt" : "1604482920642"
          }
        }, {
          "_RW_.rwbm.rwztbm" : "20",
          "_RW_.rwbm.jssj" : {
            "$lt" : "1604482800642"
          }
        }, {
          "_RW_.rwbm.rwztbm" : "50",
          "_RW_.rwbm.yssj" : {
            "$lt" : "1604482920642"
          }
        }, {
          "_RW_.rwbm.rwztbm" : "55",
          "_RW_.rwbm.yssj" : {
            "$lt" : "1604482920642"
          }
        }, {
          "_RW_.rwbm.rwztbm" : "25"
        }],
      "lrrqLong" : {
        "$gte" : "1604419200000",
        "$lt" : "1604592000000"
      }
    },
    "u" : {
      "$set" : {
        "_RW_.rwbm.rwztbm" : "10"
      }
    },
    "multi" : true,
    "upsert" : false
  },
  "user" : "cp@123"
};

function circleKey(commandObj){
    if(typeof commandObj ==='object'){
        for(var key in commandObj){
            if((key+"").indexOf('rwbm')>-1){
                return true;
            }
            if(typeof commandObj[key] !='object'){
                if((key+"").indexOf('rwbm')>-1){
                    return true;
                }
            }else{
                var rs=circleKey(commandObj[key]); 
                if(rs===true){
                    return true;
                }
            }
        }
    }
}

var result = circleKey(cd);
document.body.append(result);
 </script>
</html>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值