1

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]
2
  • 1
    Unclear what you are asking. If items is an array, of course, you can iterate over it, but this.$data.items[i] should be this.items[i]. Commented Nov 29, 2016 at 11:17
  • Please add more details, on what are you trying to do, what error you are getting. Commented Nov 29, 2016 at 13:35

2 Answers 2

2

yes

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

Sign up to request clarification or add additional context in comments.

Comments

2

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);
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.