简体   繁体   English

我如何遍历数组以提取ID号JavaScript

[英]How can I loop through an array to pull out an Id number javascript

I have a list that is coming from the db and creates a list of checkbox inputs. 我有一个来自数据库的列表,并创建了一个复选框输入列表。 When the user clicks on the checkbox it will populate only that item. 当用户单击复选框时,它将仅填充该项目。 What I want to do to begin with is check the status of the checkbox. 首先,我要检查复选框的状态。 If it's checked I want to console.log the systemId and the operator name to compare to make sure they match. 如果已选中,则我要console.log systemId和操作员名称进行比较以确保它们匹配。 here is my code: 这是我的代码:

        $(".wellProducer").click(function(){
            if(this.checked == true){
                console.log(wells["SystemId"]);
                console.log(wellProducers["Operator"]);
            }
        });

The .wellProducer is the class of the input checkbox. .wellProducer是输入复选框的类。 What I have populating right now is all the systemId's and operators, but I want to compare them to see if they match. 我现在填充的是所有systemId和操作符,但是我想比较它们以查看它们是否匹配。

for(var i = 0; i < wells.SystemId; i++) {
    if (wells.SystemId[i] == wells.Operator[i]) {
        console.log(wells.SystemId[i]);
    }
}

Asuming they are strings, and that they are put in the same order. 假设它们是字符串,并且以相同的顺序放置。 Otherwise comment this answer and I'll see what I can change to make it work. 否则,请评论此答案,然后我将进行更改以使其起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM