I would like to convert this piece of code to ES-6. So the for loop in the first example I used needs to be a for of loop. What happens is in the second version that the percentage calculation works just as expected as i can see in the console but it doesn't show in the UI. The older, first method works fine. How come?
// This one works fine
displayPercentages: function(percentages) {
var fields =
document.querySelectorAll(DOMstrings.expensesPercLabel);
var nodeListForEach = function(list, callback) {
for(var i = 0; i < list.length ; i++) {
console.log(list[i], i)
callback(list[i], i)
}
};
nodeListForEach(fields, function(el, index){
if(percentages[index] > 0){
el.textContent = percentages[index] + '%'
}else{
el.textContent = '---';
}
});
},
// Second version has a problem showing percentages in the UI
displayPercentages: function(percentages) {
var fields = document.querySelectorAll(DOMstrings.expensesPercLabel);
var nodeListForEach = function(list, callback) {
for(let [el, index] of list.entries()) {
console.log(el, index)
callback(el, index)
}
};
nodeListForEach(fields, function(el, index){
if(percentages[index] > 0){
el.textContent = percentages[index] + '%'
}else{
el.textContent = '---';
}
});
},