Question: i have a very long array of points like so: 

```
        latlngs: [
      [3.063895, 50.636767],
      [3.06339, 50.637233],
      [3.063309, 50.637278],
      [3.063254, 50.637288],
      [3.063103, 50.637267],
      [3.061939, 50.636762],
      [3.059679, 50.635821],
      [3.056687, 50.634532],
      [3.067972, 50.628265],
      [3.068189, 50.628169],
      [3.068389, 50.628159],
      [3.06959, 50.628201],
      [3.075613, 50.629068],
      [3.077604, 50.629383],...
      // 4500 array more
      ]

```

And i would like to loop on one on n element on it to make the computation less intensive. For example i would like to loop on 1 on 6 elements. What would be the best way to do that ?

Answer: 
A `for` loop seems like the simplest solution:

```
for (let n = startIndex; n < endIndex; ++n) {
    const entry = theArray[n];
    // ...
}

```

You can also create an array from a slice of an array, but it...creates an array (and, in this example, an iterator object, though that may get optimized away):

```
for (const entry of theArray.slice(startIndex, endIndex)) {
    // ...
}

```

---

In a comment, [user753642 said](https://stackoverflow.com/questions/59211334/looping-over-certain-elements-on-an-array-in-javascript/59211384#comment104639292_59211334) they think you mean *"...elem 0, elem 6, elem 12"*. If so, you'd use `n += 6` rather than `++n`:

```
for (let n = startIndex; n < endIndex; n += 6) {
    const entry = theArray[n];
    // ...
}

```

That assumes you know `endIndex` is `<= theArray.length`. If you're accepting it from outside you may not know that, in which case:

```
for (let n = startIndex, end = Math.min(theArray.length, endIndex); n < end; n += 6) {
    const entry = theArray[n];
    // ...
}

```
A simple `for` loop is enough

```
for (let index = 0; index < latlngs.length; index+= 6) {

  // do whatever computation you need with latlngs[index]

}

```