Jan Jan - 1 month ago 8
Javascript Question

Gridview in javascript, identifying a series of numbers

Given this sample grid and a number

n
:

1 2 3
4 5 6
7 8 9
10 11 12


i want to select 1, 3, 4, 6, 7, 9, 10, 12... so on and so forth.

the odd numbers, you can use
modulus %2 == 1


for the rest how do you do this?

Answer

You could use a test, which skips a modulo 3 value, moved by an offset.

var i;
for (i = 1; i <= 12; i++) {
    if ((i + 1) % 3) {
        console.log(i);
    }
}

Comments