Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
iterate for each element of variable, got TypeError

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use in for Objects. of is for iterating over Arrays.

for (const key in my_var) {
  console.log(key, my_var[key])
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!