I am storing values in an array like this. I want to be able to test the values contained in Routenumber and SerialNumber. If Routenumber == "" do something if SerialNumber == "None" do something
How can I acheive this in my for statement? What I have below just returns an object.
$('#ValidateAcctAssign').click(function() {
var values = [];
$("#container-grid input[name=CatId]:checked").each(function() {
row = $(this).closest("tr");
values.push({
CatId: $(row).find("input[name=CatId]").val(),
Routenumber: $(row).find("td div.routenum").text(),
SerialNumber: $(row).find("td div.primrep").text()
});
});
console.log(values);
var count = 0;
for (var i = 0; i < values.length; i++) {
if (values[1] == "" || values[2] == "None") {
count = count + 1;
}
}
console.log(count);
});
To access to object's property you can use dot notation
You need this for
loop:
for (var i = 0; i < values.length; i++) {
if (values[i].Routenumber == "" || values[i].SerialNumber == "None") {
count = count + 1;
}
}
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.