I would like to do something for each element in my_var:
// get selected rows of DataTable
let table_data = dtMember.rows({ selected: true }).data();
const COL_INDEX = 4 ; // column index of the column to count
let my_var = table_data.reduce(function (col_to_count, currentValue) {
if (currentValue[COL_INDEX] in kulturen) {
col_to_count[currentValue[COL_INDEX]]++;
}
else {
col_to_count[currentValue[COL_INDEX]] = 1;
}
return col_to_count;
}, {});
I tried:
for (const element of my_var) {
console.log(element);
}
But getting the
TypeError: my_var is not eterable
I tried also my_var.entries() and my_var.keys() which are suggested on the help page of firefox but let to is not a function
How can I do it correctly?
Use in for Objects. of is for iterating over Arrays.
for (const key in my_var) {
console.log(key, my_var[key])
}