get every 7th number in javascript

You can achieve this by using a loop to iterate over an array of numbers, and use the modulus operator to check if the current index is a multiple of 7.

index.tsx
let numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];

for(let i = 0; i < numbers.length; i++){
  if(i % 7 === 0){
    console.log(numbers[i]); // prints every 7th number
  }
}
176 chars
8 lines

In the above code, i % 7 checks if the current index is divisible by 7 without leaving any remainder. If it is divisible, then the current element of the array at that index is printed out using console.log().

gistlibby LogSnag