I've been using C# for quite some time, but I'm facing a challenge with a basic concept in the JavaScript part of my project. The following code snippet is part of a larger function I've written:
addPaymentsToBreakdown = function () {
for (var count = 0; count < checkedPayments.length; count++) {
(function (count) {
console.log(checkedPayments[0][count].value);
})(count);
}
}
This code snippet uses an array 'checkedPayments' that is properly instantiated elsewhere. However, I'm struggling to understand why I can't simply use the 'count' variable to iterate over the second tier of indexes in the array. I can access individual indexes manually or print the entire array using console.log(), but when I try to combine the 'count' variable with the array index, I encounter issues. The error message I'm receiving is
Uncaught TypeError: Cannot read property 'value' of undefined.
Can someone help me understand why this isn't working and provide a solution? Thank you.