0
<table style="cursor:default">
                    <tbody>
                        <tr v-for="j in status_data.length/2">
                            <td class="w3-border w3-border-black w3-round-large w3-center" :bgcolor="getColor(status_data[j-1].MESSAGE_CODE)">{{ status_data[j-1].PROCESS_CODE }}</td>
                            <td class="w3-border w3-border-black w3-round-large w3-center" :bgcolor="getColor(status_data[j].MESSAGE_CODE)">{{ status_data[j].PROCESS_CODE }}</td>
                        </tr>
                    </tbody>
                </table>

how can i control value of j in above code , i want it is like

for i in status_data.length/2 do action i=i+2

i want to increment value by 2 in every iteration .

1 Answers1

0

If you want it by pairs, go through the array and collect pairs whenever the index is an even number.

status_data
.map((v, i) => i%2 === 0 ? arr.slice(i, i+2) : [])
.filter(x => x.length > 0)
console> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
.map((v, i) => i%2 === 0 ? arr.slice(i, i+2) : [])
.filter(x => x.length > 0)

// will return an array like [[1,2],[3,4],[5,6],[7,8],[9,10],[11,12]]

Beware that this will ignore the last element if your array has an odd number of elements

S.B
  • 827
  • 6
  • 7