Imagine you have an array with 10 items and wanted to divide it up into a set of five's to fit with your design objective.
Several common solutions to this problem I've seen in the wild include:
- Hard-coding the solution
- Creating two separate arrays
So, here's a simpler and better solution to do it with one array in VueJS:
<p
v-for="(item, index) in yourArray.slice(start, end)"
:key="index">
{{ item.topic }}
</p>
The best thing about this solution is, you can dynamically set the start
and end
values, for example, using inputs from the user.
Hope that helps, cheers!
Top comments (0)