简体   繁体   中英

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. 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. What I have populating right now is all the systemId's and operators, but I want to compare them to see if they match.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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