build a list of the numbers from 1 to 101 in typescript

Here's how to build a list of the numbers from 1 to 101 in TypeScript:

index.ts
let numbers: number[] = [];

for (let i = 1; i <= 101; i++) {
  numbers.push(i);
}

console.log(numbers); // outputs [1, 2, 3, ..., 100, 101]
142 chars
8 lines

We start by declaring an empty array called numbers that will hold our list of numbers. Then we use a for loop that starts at 1 and increments up to 101. Inside the loop, we use the push() method to add each number to the numbers array. Finally, we log the resulting array to the console.

This will produce the following output:

index.ts
[1, 2, 3, ..., 100, 101]
25 chars
2 lines

related categories

gistlibby LogSnag