loop from 1 to 10 in javascript

You can use a for loop to loop from 1 to 10 in JavaScript:

index.tsx
for (var i = 1; i <= 10; i++) {
  console.log(i);
}
52 chars
4 lines

This loop will start at 1, and continue looping as long as i is less than or equal to 10. On each iteration of the loop, the code inside the braces will be executed. In this case, we're simply logging the value of i to the console.

So when you run this code, you should see the numbers 1 through 10 printed to the console.

related categories

gistlibby LogSnag