build a list of the numbers from 1 to 100 in javascript

To build a list of numbers from 1 to 100 in javascript, we can use a for loop to iterate from 1 to 100 and add each number to an array.

Here's the code:

index.tsx
let numbers = [];

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

console.log(numbers); // [1, 2, 3, 4, 5, ..., 99, 100]
129 chars
8 lines

In this code, we start with an empty array numbers. We then use a for loop to iterate from 1 to 100 (inclusive) using the loop variable i. Inside the loop, we add i to the array using the .push() method. After the loop finishes, we log the array to the console using console.log().

gistlibby LogSnag