在关联数组javascript中搜索值

Search value in associative array javascript

本文关键字:搜索 javascript 关联 数组      更新时间:2023-09-26

JAVASCRIPT

    var error = new Object ({'1a':'1','1b':'1','2a':'1'}); // like this I have defined around 200 values
    if (some condition is true)
          error[id] = 0;  // id is selected dynamically ( '1a' or '1b' or what ever)

当所有这些都完成后,我想检查Object错误中的任何一个是否仍然具有值"1"。我使用了以下内容,但似乎不起作用。。

    for ( i in error)
          if(error[i].value == '1')   -some code-  // this line gives error, not able to read value

什么应该是正确的方法。。。??

只需删除.value:

if(error[i] == '1'){...}