0

Is there any way to iterate array in vue.js from a particular index to another particular index.

for example i have an array with 100 objects,I want to create a view of 30 objects from 30th index to 60th index.

we can make hide remaining index objects with v-show or v-if with conditions.but i don't want to do like that.

Any other suggestion.?

2 Answers 2

4

Use computed properties for example

in your component

computed:{
    partObject(){
      return this.objects.slice(30,61);
    }
  }

now in your component template you iterate over this computed prop

 <li v-for="item of partObject">
        {{item}}
      </li>
Sign up to request clarification or add additional context in comments.

Comments

0

You could use a v-for to iterate over the indexes and then print the corresponding elements.

Something like this

<div v-for="index in 30">{{objects[index+30]}}</div>

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.