Kendall
Kendall

Reputation: 5255

Looping through data array properties in VueJS

In vuejs you can do list rendering in the template like

<td v-for="item in items"></td>......

But can you iterate over that same data array property like....

for(var i = 0; i < this.items.length; i++)
 this.$data.items[i]

Upvotes: 1

Views: 5938

Answers (2)

Aur&#233;lien
Aur&#233;lien

Reputation: 1655

this post is quite old, but this can be useful to anyone who wants to iterate into an array of object.

Instead of:

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

You can do this a little bit more concisely and more readable (in my opinion):

this.items.forEach((item) => {
  console.log(item);
})

Upvotes: 2

GuyC
GuyC

Reputation: 6574

yes

Just don't worry about the this.$data.items, instead this.items, although it would also work ...

Upvotes: 2

Related Questions