我有一个看起来像的对象数组

data =
[
  {
    "AccountType":"Client",
    "DeploymentList":
      {
        "-L3y8Kpl5rcvk-81q004":
        {
          "DeploymentKey":"-L3y8Kpl5rcvk-81q004",
          "DeploymentName":"Testing 3"
        }
      }
  },
  {
    "AccountType":"Client",
    "DeploymentList":
      {
        "-L3yGFxXQ8XbeK8b2GSF":
        {
          "DeploymentKey":"-L3yGFxXQ8XbeK8b2GSF",
          "DeploymentName":"Testing 1"

        }

      }
  }
]


我想遍历这些数据并想找到一个字符串。在此数据中,我想查找
javascript - 遍历对象数组并找到特定的键-LMLPHP

到目前为止,我尝试过的是

for (let d of this.data) {
      for(let a of d.DeploymentList){
        if(a.$key==="-L3y8Kpl5rcvk-81q004"){
          // Inside the condition
    }
}


但这是行不通的。我该如何实现?

最佳答案

您可以按以下方式检查密钥是否存在,

for (let d of this.data) {
      for(let a of d.DeploymentList){
        if(a["-L3y8Kpl5rcvk-81q004"]){
          // Inside the condition
    }
}

09-17 11:52