• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

104
Views
Is there a better way, to iterate through

How to iterate in a better way through A and B?

Data structure A:

AbsatzNrSaetzeText: { [key: string]: string[] };

Data structure B:

 AbsatzNrSaetzeText: Record<number, string[]>;

Is there a better way, to get that value:

     for (var i = 0; i < this.UI_Seiten.length; i++) {
      for (var j in this.UI_Seiten[i].AbsatzNrSaetzeText) {
        for (var k = 0; k < this.UI_Seiten[i].AbsatzNrSaetzeText[j.valueOf()].length; k++) {
          console.log(this.UI_Seiten[i].AbsatzNrSaetzeText[j.valueOf()][k]);
        }
      }
    }
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For iterable objects (like arrays), there is no need to reference the index in order to iterate over the values - for..of allows for significantly cleaner code, by putting the value being iterated over directly into an identifier that can be used in later loops.

Use Object.values instead of for..in, since you don't care about the key on the object, only about the value.

for (const seiten of this.UI_Seiten) {
    for (const arr of Object.values(seiten.AbsatzNrSaetzeText)) {
        for (const str of arr) {
            console.log(str);
        }
    }
}
about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error