For loop within a method

checkAuthor() {
      for ( var i = 0; i < authors.length; i++ ) {
          console.log(authors[i]);
        };
     }

Why is does not work?

Hi. Is author in your data? If so it must be refered to as this.authors

2 Likes

Assuming authors is a data or prop property, you need to use this.

this.authors.length
2 Likes
for (let i = 0; i < this.authors.length; i++) {
    this.authors[i];
  }

It still does not work!

I’m just trying to check if this loop works by printing console.log(this.author[i].name);

Hi. Can you show all of the code so we can see how authors is defined and how this code is called?

1 Like

Thanks Johan, I figured it out!

1 Like

What was the problem?

I had to declare i out of the loop instead of doing direct declaration!